Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. trouble using the Qt provided ftp example
QtWS25 Last Chance

trouble using the Qt provided ftp example

Scheduled Pinned Locked Moved Solved General and Desktop
ftpnetwork
9 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mar0029
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        @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?

        M Offline
        M Offline
        mar0029
        wrote on last edited by mar0029
        #3

        @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.

        mrjjM 1 Reply Last reply
        0
        • M mar0029

          @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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          try
          progressDialog->hide();
          for test.

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

          M 1 Reply Last reply
          0
          • mrjjM mrjj

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

            try
            progressDialog->hide();
            for test.

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

            M Offline
            M Offline
            mar0029
            wrote on last edited by
            #5

            @mrjj

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

            mrjjM 1 Reply Last reply
            0
            • M mar0029

              @mrjj

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              M 1 Reply Last reply
              0
              • mrjjM mrjj

                @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.

                M Offline
                M Offline
                mar0029
                wrote on last edited by mar0029
                #7

                @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!

                mrjjM 1 Reply Last reply
                0
                • M mar0029

                  @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!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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 :)

                  M 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @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 :)

                    M Offline
                    M Offline
                    mar0029
                    wrote on last edited by mar0029
                    #9

                    @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);

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved