Results 1 to 2 of 2

Thread: QHttp readAll() return empty QbyteArray

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QHttp readAll() return empty QbyteArray

    Hi!

    I'm a beginner to Network programming and I'm trying to write a simple console application which return html source from server.

    this is the code

    Qt Code:
    1. void Downloader::doDownload()
    2. {
    3. QHttp *http = new QHttp(this);
    4.  
    5. http->setHost("c-studios.host56.com");
    6. http->get("/index.html");
    7.  
    8. connect(http, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
    9. connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(responseHeaderReceived(QHttpResponseHeader)));
    10. connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
    11. connect(http, SIGNAL(readyRead(QHttpResponseHeader)), this, SLOT(showHtml()));
    12.  
    13.  
    14. }
    15.  
    16. // ....
    17.  
    18. void Downloader::responseHeaderReceived(const QHttpResponseHeader &resp)
    19. {
    20. qDebug() << "Size: " << resp.contentLength(); //works fine. show correct length
    21. qDebug() << "Type: " << resp.contentType(); // works fine
    22. qDebug() << "Status: " << resp.statusCode(); // fine return 200
    23. }
    24.  
    25. void Downloader::requestFinished(int id, bool error)
    26. {
    27. if(error)
    28. {
    29. qDebug() << "Error!";
    30. }
    31. else
    32. {
    33. qDebug() << "Ok!";
    34. }
    35. }
    36.  
    37. void Downloader::showHtml()
    38. {
    39. QString html(http->readAll()); //this is the problem. QString is empty
    40. qDebug() << html;
    41. }
    To copy to clipboard, switch view to plain text mode 

    when i call http->readAll() it's return empty byte array. I can't fugure out what is the problem. someone help please. thanks

  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: QHttp readAll() return empty QbyteArray

    I'm guessing there is no data yet ready, just the headers. You can read your data in requestFinished() if you want. Or better yet use QNetworkAccessManager instead of the deprecated QHttp.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 2nd January 2013, 09:48
  2. Replies: 1
    Last Post: 18th February 2011, 11:05
  3. Question on QByteArray::QHttp::readAll()
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 2
    Last Post: 17th June 2010, 15:51
  4. QT-wince and QHttp::readAll() trouble....
    By AcerExtensa in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 12th June 2008, 09:40
  5. QHTTP Readall() function
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 17th April 2007, 00:55

Tags for this Thread

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.