Results 1 to 3 of 3

Thread: QHTTP Readall() function

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default QHTTP Readall() function

    I am attempting to use the following function to read a plain text file from a webserver to populate a simple text string of the version number. The web file only has "0.1" in it. It will be the version number. This will eventually be an automatic version check, but i cannot seem to get the QHTTP readall() function to work.

    I can see that the connection to the webserver is made (via wireshark) and the proper file is accessed, but the contents are never place in the "version" variable.

    no errors are generated from this, only "Automatic Version Check" is written to Debug and ui.statusLogs is updated with "Version is:" no Version number from http though..

    here is the function.

    Qt Code:
    1. void Porcupine::checkVersion()
    2. {
    3. qDebug("Automatic Version Check");
    4.  
    5. versionHttp = new QHttp();
    6. versionHttp->setHost("192.168.1.111", 80);
    7. versionHttp->get("/version.txt");
    8.  
    9. QString version = versionHttp->readAll();
    10.  
    11. ui.statusLogs->append(tr("Version is: %1")
    12. .arg(version));
    13. }
    To copy to clipboard, switch view to plain text mode 



    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHTTP Readall() function

    QHttp needs time to fetch the result --- it will emit a signal when the result is available and only then you can read it.

  3. The following user says thank you to jacek for this useful post:

    nbkhwjm (17th April 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: QHTTP Readall() function

    Great This worked

    Qt Code:
    1. void Porcupine::checkVersion()
    2. {
    3. qDebug("Automatic Version Check");
    4.  
    5. versionHttp = new QHttp();
    6.  
    7. connect(versionHttp, SIGNAL(done(bool)), this, SLOT(showVersion()));
    8.  
    9. versionHttp->setHost("192.168.1.111", 80);
    10. versionHttp->get("/version.txt");
    11.  
    12. }
    13.  
    14. void Porcupine::showVersion()
    15. {
    16. QString version = versionHttp->readAll();
    17.  
    18. ui.statusLogs->append(tr("Version is: %1")
    19. .arg(version));
    20. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  3. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  4. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

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.