Results 1 to 1 of 1

Thread: I don't receive QFtp::done(bool) signal when off-line, I can't QFtp::abort() its task

  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default I don't receive QFtp::done(bool) signal when off-line, I can't QFtp::abort() its task

    Hi everybody,
    after having two-week-lasting holiday I came back to continue my small project.
    My application is intended to download a small file at startup depending on url given in settings. If no settings are present, there is a hard-coded link.

    Everything works fine if we are on-line. The problem grows when we start my application while off-line.

    The method below is called in constructor:
    Qt Code:
    1. bool MyWidget::DownloadData() {
    2. settings = new QSettings("MTR","MTR::Mastermind 1.0 PL");
    3. if(settings->value("conciseDataURL") == QVariant())
    4. settings->setValue("conciseDataURL", QVariant("ftp://ftp*********************"));
    5. else
    6. settings->setValue("conciseDataURL", settings->value("conciseDataURL"));
    7.  
    8. QUrl urlek(settings->value("conciseDataURL").toString()); //we posses an url to the file with data
    9.  
    10. bool errorUrl = false;
    11. if(!urlek.isValid()) errorUrl = true;
    12. if(urlek.scheme() != "ftp") errorUrl = true;
    13. if(urlek.path().isEmpty()) errorUrl = true;
    14. if(errorUrl) return false;
    15.  
    16. file.setFileName(QString("name.ofFile"));
    17. if(!file.open(QIODevice::WriteOnly)) return false;
    18.  
    19. connect(&ftp, SIGNAL(done(bool)),this,SLOT(downloadingDone(bool)));
    20.  
    21. ftp.connectToHost(urlek.host(), urlek.port(21));
    22. ftp.login();
    23. ftp.get(urlek.path(), &file);
    24. ftp.close();
    25.  
    26. return true;
    27. }
    To copy to clipboard, switch view to plain text mode 

    If we are off-line, there should be emitted done(bool) signal with its argument of type bool equal true.

    Here you have body of downloadingDone(bool) slot:
    Qt Code:
    1. void MyWidget::downloadingDone(bool weveGotError) {
    2. file.close(); // we close device as our download has finished (either succedded or failed)
    3. if(weveGotError) return; // if we failed, we stop our code
    4.  
    5. file.open(QIODevice::ReadOnly);
    6. QDataStream in(&file);
    7. int magicNumber;
    8. QString host;
    9. QString login;
    10. QString password;
    11. in >> magicNumber >> host >> login >> password;
    12. file.close();
    13. //usuwanie pliku
    14. file.remove();
    15. DownloadFromDatabase(host,login,password);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Then DownloadFromDatabase() :
    Qt Code:
    1. bool MyWidget::DownloadFromDatabase(const QString &host,const QString &login,const QString &password) {
    2. if(!createConnection(host,login,password)) return false;
    3. QSqlQuery query;
    4. query.exec("SELECT mGR_secsOfPlay, mGR_timeAndDate, mGR_playername FROM mastermindGlobalResults ORDER BY mGR_secsOfPlay ASC");
    5. rekordyGLobalne.clear();
    6. while(query.next()) {
    7. MTR::Record r(query.value(2).toString(),query.value(0).toUInt(),query.value(1).toDateTime());
    8. rekordyGLobalne.append(r);
    9. }
    10. return true;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Then

    Qt Code:
    1. bool MyWidget::createConnection(const QString &host,const QString &login,const QString &password) {
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    3. db.setHostName(host);
    4. db.setDatabaseName("********");
    5. db.setUserName(login);
    6. db.setPassword(password);
    7. if(!db.open()) return false;
    8.  
    9. return true;
    10. }
    To copy to clipboard, switch view to plain text mode 

    If I close my application while being off-line all the time the application runs, the program freezes. In other words it stops responding to user interactions and does not dissapear. What's more, all the time the console output is blocked!

    Here you have destructor:
    Qt Code:
    1. MyWidget::~MyWidget() {
    2. ftp.abort();
    3. QVariant var(packRecords(rekordyLokalne));
    4. settings->setValue("rekordyLokalne",var);
    5. settings->sync();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mtrpoland; 23rd September 2007 at 14:16.

Similar Threads

  1. QTextStream : Remove a Line?
    By kaydknight in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2011, 18:15
  2. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  3. QGLWidget bug
    By Wizard in forum Qt Programming
    Replies: 11
    Last Post: 31st August 2007, 11:23
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.