Seite 1 von 1

QFtp-Programm hängt nach ftp->abort() -> HILFE

Verfasst: 29. März 2010 16:01
von felixwiewel
HI,
ich habe ein kleines ftp programm geschrieben. Läuft alles auch einigermaßen gut. Wenn ich allerdings etwas downloade und dann den download abbreche hängt das Programm und ich kann nicht mal die Verbindung trennen. Hier die code stellen auf die sich mein problem bezieht:

Code: Alles auswählen

void MainWindow::ftp_download()
{
    filename = QFileDialog::getSaveFileName(this,"Download","~/"+ui->listWidget->currentItem()->text());
    file = new QFile(filename);
    if (file->open(QIODevice::WriteOnly))
    {
        progress = new QProgressDialog("Download","Cancel",0,100,this);
        connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)),
                this,SLOT(ftp_setprogress(qint64,qint64)));
        connect(progress,SIGNAL(canceled()),
                ftp,SLOT(abort()));
        ftp->get(currentdir+ui->listWidget->currentItem()->text(),file);
        progress->exec();
    }
    else
    {
        QMessageBox(QMessageBox::Warning,"Error",file->errorString());
    }
}
Funktion zum update des ProgressDialog:

Code: Alles auswählen

void MainWindow::ftp_setprogress(qint64 read, qint64 total)
{
    progress->setRange(0,total);
    progress->setValue(read);
}
Danke für eure hilfe im Vorraus.

Verfasst: 29. März 2010 16:37
von pfid
Und wo sind da die Stellen die den Download abbrechen und den Absturz verursachen? :?:

Verfasst: 29. März 2010 16:52
von felixwiewel
Ich verbinde einfach das Canceled Signal vom Progressdialog mit dem Abort-Slot von ftp. Wenn ich also auf cancel im Progressdialog klicke sollte auch der Abort-Slot von ftp aufgerufen werden.

Code: Alles auswählen

void MainWindow::ftp_download() 
{ 
    filename = QFileDialog::getSaveFileName(this,"Download","~/"+ui->listWidget->currentItem()->text()); 
    file = new QFile(filename); 
    if (file->open(QIODevice::WriteOnly)) 
    { 
        progress = new QProgressDialog("Download","Cancel",0,100,this); 
        connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)), 
                this,SLOT(ftp_setprogress(qint64,qint64))); 
---------------------------------------------------------------------------
# Hier wird das Canceled Signal mit dem Abort-Slot verbunden #
---------------------------------------------------------------------------
        connect(progress,SIGNAL(canceled()), 
                ftp,SLOT(abort())); 
----------------------------------------------------------------------------
        ftp->get(currentdir+ui->listWidget->currentItem()->text(),file); 
        progress->exec(); 
    } 
    else 
    { 
        QMessageBox(QMessageBox::Warning,"Error",file->errorString()); 
    } 
}
Das Problem besteht nun darin das wenn ich bei dem Progressdialog auf Cancel klicke sich das ganze Programm aufhängt bis irgendwann kommt das der Download abgeschlossen sei.