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.
-
@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 inFtpWindow::downloadFile
whereprogressDialog->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. -
@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.
-
@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 didtimer = 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);