Results 1 to 2 of 2

Thread: QHttp

  1. #1
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QHttp

    Hi all,

    I am quite new to QHttp and now I have my first Problem with a QHttp request.

    hier my Code:

    Qt Code:
    1. void MainWindow::on_pb_getIMDB_clicked()
    2. {
    3. httpRequestAborted = false;
    4.  
    5. QHttpRequestHeader header("GET", "/find?s=all&q=300&x=15&y=7 HTTP/1.1");
    6. header.setValue("Host", "german.imdb.com");
    7. header.setValue("User-Agent", "Mozilla/5.0 (X11; U; LinuMozx i686; de; rv:1.9.0.1) Gecko/2008070400 SUSE/3.0.1-8.1 Firefox/3.0.1");
    8. header.setValue("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    9. header.setValue("Accept-Language", "de-ch,de;q=0.8,de-de;q=0.6,en-us;q=0.4,en;q=0.2");
    10. header.setValue("Accept-Encoding", "gzip,deflate");
    11. header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    12. header.setValue("Keep-Alive", "300");
    13. header.setValue("Connection", "keep-alive");
    14.  
    15. http->setHost( "german.imdb.com" );
    16. httpGetId = http->request( header );
    17. }
    18.  
    19. void MainWindow::httpRequestFinished( int requestId, bool error )
    20. {
    21. if (requestId != httpGetId)
    22. return;
    23.  
    24. if ( error )
    25. {
    26. QMessageBox::information( this, tr( "HTTP" ),
    27. tr( "Download failed: %1." )
    28. .arg( http->errorString() ));
    29. }
    30. else
    31. {
    32. QByteArray m_data = http->readAll();
    33.  
    34. qDebug() << QString::number( m_data.size() );
    35. QString text(m_data.data());
    36. te_test->setText( text );
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    The signals and slots are working correctly. The size I receive is around 8298 bytes, but I can not read them. I mean, I should receive some HTML stuff (I think so) but if I try to put them into a file or a text field it does not show me anything.

    Do I something wrong? May someone give me an advice please?

    Regards
    big4mil

  2. #2
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp

    To copy data to a QString you could probably do something like this:

    Qt Code:
    1. QTextIStream s(m_data);
    2. QString text = s.readAll();
    3. te_test->setText(text);
    To copy to clipboard, switch view to plain text mode 

    But pay attention to the documentation of readAll()
    Reads the entire content of the stream, and returns it as a QString. Avoid this function when working on large files, as it will consume a significant amount of memory.

Similar Threads

  1. new QHttp() Error
    By fengtian.we in forum Qt Programming
    Replies: 7
    Last Post: 6th October 2010, 17:56
  2. problem in using QHttp
    By Ferdous in forum Newbie
    Replies: 4
    Last Post: 10th September 2008, 12:07
  3. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41
  4. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39
  5. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19

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
  •  
Qt is a trademark of The Qt Company.