trouble using the Qt provided ftp example



  • Hello!

    I've opted to use QFtp instead of QNetworkAccessManager so that I could use the example here directly in an app I'm building. Trouble is, whenever I launch the example, what I assume is the progress bar pops up behind the main window, without anything having called it. It looks like this, and the relevant code is here, I think:

     void FtpWindow::downloadFile()
     {
    QString fileName = fileList->currentItem()->text(0);
     //
    if (QFile::exists(fileName)) {
        QMessageBox::information(this, tr("FTP"),
                                 tr("There already exists a file called %1 in "
                                    "the current directory.")
                                 .arg(fileName));
        return;
    }
    
    file = new QFile(fileName);
    if (!file->open(QIODevice::WriteOnly)) {
        QMessageBox::information(this, tr("FTP"),
                                 tr("Unable to save the file %1: %2.")
                                 .arg(fileName).arg(file->errorString()));
        delete file;
        return;
    }
    
    ftp->get(fileList->currentItem()->text(0), file);
    
    progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
    downloadButton->setEnabled(false);
    progressDialog->exec();
    }
    

    Whenever the progress dialog is closed on it's own, the app crashes.


  • Qt Champions 2016

    @mar0029 said:
    Hi
    That sounds odd as
    it only news it in ftpwindow.cpp
    progressDialog = new QProgressDialog(this);

    What about setting break point at
    progressDialog->exec();
    and look at call stack to see who calls it?



  • @mrjj
    Hello again!

    Something really strange. I commented out all of the functions in ftpwindow.cpp except for FtpWindow::FtpWindow and the dialog box still opened.

    I did something similar and commented all lines having to do with progressDialog and it didn't open, which is good.

    EDIT:
    Setting a break point in FtpWindow::downloadFile where progressDialog->exec() is called does nothing. In the same manner, I put a debug statement in every function and upon opening the app, only one debug statement is sent.


  • Qt Champions 2016

    @mar0029
    Hi
    just after
    progressDialog = new QProgressDialog(this); ???

    try
    progressDialog->hide();
    for test.

    Also did u set breakpoitn and looked if exec() is called?



  • @mrjj

    Adding progressDialog->hide() after progressDialog = new QProgressDialog(this); did nothing.


  • Qt Champions 2016

    @mar0029
    ok so its not created visible for some reason.

    You must use breakpoint then.
    at
    progressDialog->exec();
    and see who calls it.

    ( if its even why , its shown at start)

    I can have a look if u zip project and send via dropbox or onedrive.



  • @mrjj
    The stack doesn't show anything calling it. I'm not too great at using the debugger so I'm probably doing it wrong.
    Here is the link to Dropbox.

    Thank you for your time!


  • Qt Champions 2016

    @mar0029
    Hi
    I dont have ftp module it seems so cant run.
    Win 10, Qt 5.6 Mingw compiler.

    However, I saw something

    int main(int argc, char *argv[])
    {
        qInstallMsgHandler(crashingMessageHandler);
    
        QApplication a(argc, argv);
    ...
        FtpWindow ftpWin;
        ftpWin.show();
    
        return ftpWin.exec();
    }
    

    You call first ftpWin.show() and then ftpWin.exec();
    Normally that would be
    a.exec(); so applications event loops runs.

    Not sure if it can do what u see.
    Just thought I should mention it :)



  • @mrjj
    I could never figure out what was calling progressDialog. So after progress dialog was created, I did

    timer = new QTimer(this);
    timer->setSingleShot(true);
    timer->start(5000);
    connect(timer, SIGNAL(timeout()), this, SLOT(testing()));
    

    and

     void FtpWindow::testing()
     {
         progressDialog->hide();
     }
    

    crude but it works. If there were a QDialog signal for isActiveWindow or hasAppeared, it would be better. But this works.

    Edit: ended up using progressDialog->setAttreibute(Qt::WidgetAttribute::WA_DontShowOnScreen, true);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.