Results 1 to 10 of 10

Thread: QFtp in a separate instances

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QFtp in a separate instances

    I tried using Ftp in my Qdialog widget to do a multiple download, and it work fine , now since i have two server that i can ping on at the same time so i tried having two instances of my dialog then download at the same time , what i noticed that the other instance of my dialog will wait for the the the other to be done downloading and then start its download ....I wanted them to be parrallel not serial download between instances of my dialog.

    Any hints guys of what should i set in QFtp?

    baray98

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp in a separate instances

    It's not a problem with QFtp, but with the fact that you have two modal dialogs and they are blocking each other. Either use non-modal dialogs (QWidget::show instead of QDialog::exec) or use a single dialog. You can also try making ftp objects independent of the dialogs, but that's more work.

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp in a separate instances

    my dialog are non-modal, i thought that was the problem, but it did not help. I noticed that that when my first dialog is in the middle of file download then once I make my other dialog to do a download , my first dialog will continue downloading until its done on that file then the waiting will happen .....( waits for the second dialog to be done with its download ) then my first dialog will resume....

    baray98

  4. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp in a separate instances

    when you said "blocking each other" meaning i can get away with using QWidget instead of QDialog as my inherited class?

    I Poped these dialog like below:

    Qt Code:
    1. void DeviceWidget::Ftp(void)
    2. {
    3. if (!m_FtpDialog)
    4. {
    5. m_FtpDialog = new FtpDialog(0);
    6. m_FtpDialog->setWindowTitle(tr("FTP Download for %1").arg(getStringName(m_config.deviceId)));
    7. }
    8.  
    9. m_FtpDialog->show();
    10. m_FtpDialog->raise();
    11. m_FtpDialog->activateWindow();
    12. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp in a separate instances

    I tried inheriting QWidget but it has different it frozen my first dialog (which was in the middle of downloading a file ) and when my other dialog downloaded the file it somehow triggered my first dialog to think that he is done with his file....

    so.. it did not work .. somehow the QFtp objects (instances) are tied together...

    still seeking for answer to my questions,

    baray98

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp in a separate instances

    Can we see some code related to ftp downloading?

  7. #7
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp in a separate instances

    my signal and slots connection
    Qt Code:
    1. ftp = new QFtp(this);
    2. connect(ftp, SIGNAL(commandFinished(int, bool)),
    3. this, SLOT(ftpCommandFinished(int, bool)));
    4. connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
    5. this, SLOT(addToList(const QUrlInfo &)));
    6. connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
    7. this, SLOT(updateDataTransferProgress(qint64, qint64)));
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void FtpDialog::downloadFile()
    2. {
    3. m_dir = QFileDialog::getExistingDirectory(this, tr("Save To Directory"),
    4. m_dir,
    5. QFileDialog::ShowDirsOnly
    6. | QFileDialog::DontResolveSymlinks);
    7. if (m_dir.isEmpty())
    8. {
    9. return;
    10. }
    11. selectedFiles = fileList->selectedItems(); // fileList is a QTreeWidget
    12. disconnect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
    13. connect(downloadButton, SIGNAL(canceled()), this, SLOT(cancelDownload()));
    14. for (int i = 0; i < selectedFiles.count(); i++)
    15. {
    16. QTreeWidgetItem* item = selectedFiles.at(i);
    17. QIcon icon = item->icon(NameColumn);
    18. icon.addFile(":/ftpSelected.png");
    19. item->setIcon(NameColumn,icon);
    20. }
    21.  
    22. for (int i = 0 ; i < selectedFiles.count(); i++)
    23. {
    24. currentFileItem = selectedFiles.at(i);
    25. fileList->setCurrentItem(currentFileItem);
    26. QString fileName = currentFileItem->text(NameColumn);
    27. done = false;
    28. if (QFile::exists(m_dir+"/"+fileName))
    29. {
    30. QMessageBox::critical(this, tr("FTP"),
    31. tr("There already exists a file called \"%1\" in "
    32. "the target directory. For safety reason,"
    33. "Delete the existing file manually in \"%2\" !")
    34. .arg(fileName)
    35. .arg(m_dir));
    36. continue;
    37. }
    38.  
    39. file = new QFile(m_dir+"/"+fileName);
    40. if (!file->open(QIODevice::WriteOnly))
    41. {
    42. QMessageBox::information(this, tr("FTP"),
    43. tr("Unable to save the file %1: %2.")
    44. .arg(fileName).arg(file->errorString()));
    45. delete file;
    46. continue;
    47. }
    48. startTime = QTime::currentTime();
    49. ftp->get(currentFileItem->text(NameColumn), file); // getting file starts here
    50. statusLabel->setText(tr("Downloading %1...to Directory %2").arg(fileName)
    51. .arg(m_dir));
    52. downloadButton->setText("Cancel Download");
    53. while(ftp->hasPendingCommands() || ftp->currentCommand()!=QFtp::None)
    54. {
    55. qApp->processEvents();
    56. }
    57. }
    58. selectedFiles.clear();
    59. downloadButton->setText("Download");
    60. disconnect(downloadButton, SIGNAL(canceled()), this, SLOT(cancelDownload()));
    61. connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
    62. }
    63.  
    64. void FtpDialog::ftpCommandFinished(int, bool error)
    65. {
    66. setCursor(Qt::ArrowCursor);
    67.  
    68. if (ftp->currentCommand() == QFtp::ConnectToHost)
    69. {
    70. if (error)
    71. {
    72. QMessageBox::information(this, tr("FTP"),
    73. tr("Unable to connect to the FTP server "
    74. "at %1. Please check that the host "
    75. "name is correct.")
    76. .arg(ftpServerLineEdit->text()));
    77. connectOrDisconnect();
    78. return;
    79. }
    80.  
    81. statusLabel->setText(tr("Logged onto %1.")
    82. .arg(ftpServerLineEdit->text()));
    83. fileList->setFocus();
    84. downloadButton->setDefault(true);
    85. connectButton->setEnabled(true);
    86. return;
    87. }
    88. if (ftp->currentCommand() == QFtp::Close)
    89. {
    90. statusLabel->setText(tr("Disconnected from %1.")
    91. .arg(ftpServerLineEdit->text()));
    92. return;
    93. }
    94.  
    95.  
    96. if (ftp->currentCommand() == QFtp::Login)
    97. ftp->list();
    98.  
    99. if (ftp->currentCommand() == QFtp::Get)
    100. {
    101. if (error)
    102. {
    103. statusLabel->setText(tr("Canceled download of %1.")
    104. .arg(file->fileName()));
    105. file->close();
    106. file->remove();
    107.  
    108. selectedFiles.clear();
    109. done = true;
    110. }
    111. else
    112. {
    113. statusLabel->setText(tr("Downloaded %1 ")
    114. .arg(file->fileName()));
    115. file->close();
    116. done = true;
    117. previousTime = QTime(0,0,0,0);
    118. previousReadBytes = 0;
    119. currentFileItem->setText(DownloadStatusColumn,QString("%1")
    120. .arg(100));
    121. currentFileItem->setIcon(NameColumn,QPixmap(":/ftpDownloaded.png"));
    122. }
    123. delete file;
    124. enableDownloadButton();
    125. }
    126. else if (ftp->currentCommand() == QFtp::List)
    127. {
    128. if (isDirectory.isEmpty())
    129. {
    130. fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr("<empty>")));
    131. fileList->setEnabled(false);
    132. }
    133. }
    134. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by baray98; 10th April 2008 at 17:53.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp in a separate instances

    Why are you using processEvents()? Why not rely on QFtp's signals?

  9. #9
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp in a separate instances

    like what for example... it thought there was nothing wrong in that but can you elaborate on the logic of not using processEvents().

    baray98

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp in a separate instances

    You are practically spinning a local event loop effectively stopping the flow and probably preventing your other window from executing its code. You should really use an event controlled approach.

    You should connect to its signals, queue requests and return from the function. When QFtp is done doing its job, it will call your slot so can do everything you want to do.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.