Results 1 to 5 of 5

Thread: Problem with QHttp / HTML source download

  1. #1
    Join Date
    Dec 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Problem with QHttp / HTML source download

    I am trying to download html source code from a website given in a line edit bar. The code for the function which does so appears below. Everything seems to work fine except i get an error "incomplete type 'QUrl' used in nested name specifier. Which I think is kind of weird since I copied this example directly out of the source documentation.

    Qt Code:
    1. void MainWindow::gethtml(){
    2. QString address = ui->lineEdit->text();
    3. ui->textEdit->setText(address);
    4. http = new QHttp;
    5. QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/index.html"));
    6. header.setValue("Host", "qt.nokia.com");
    7. http->setHost("qt.nokia.com");
    8. http->request(header);
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance!

  2. #2
    Join Date
    Dec 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Problem with QHttp / HTML source download

    I am now getting an error from the header file on the same code.
    There errors are:

    In function '~QHttpRequestHeader':
    undefined reference to '_imp__ZTV18QHttpRequestHeader' qhttp.h 148
    undefined reference to '_imp__ZN11QHttpHeaderD2Ev' qhttp.h 148

    When I click on the function and go to that line, the line is just a "{" bracket. So why is it doing this?

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with QHttp / HTML source download

    That classes are part of QtNetwork module, do you have:
    Qt Code:
    1. QT += network
    To copy to clipboard, switch view to plain text mode 
    in your .pro file?
    If not add it then Rebuild (maybe you will need Clear All too)

  4. #4
    Join Date
    Dec 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Problem with QHttp / HTML source download

    That did work, but I am having trouble dealing with the responses, since I'm not very familiar with the QHttp. I tried to set up a request in one function, then I set up a slot in the and it is supposed to run the second function listed below.

    I guess I'm not sure how to see errors or successes so I know what is going on with the QHttp request. Also, I don't think I set up the slot properly, the program compiles fine but then it says:

    Object::connect: No such signal QHttp::readyRead(http) in ..\htmldownload\mainwindow.cpp:12
    Object::connect: (receiver name: 'MainWindow')


    The request function
    Qt Code:
    1. void MainWindow::gethtml(){
    2. QString address = ui->lineEdit->text();
    3.  
    4. http = new QHttp;
    5. QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/index.html"));
    6. header.setValue("Host", "qt.nokia.com");
    7. http->setHost("qt.nokia.com");
    8. http->request(header);
    9.  
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    The Slot
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. http = new QHttp;
    7. connect(http, SIGNAL(readyRead(http)), this, SLOT(readthetext()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Code I'm hoping will run when the readReady signal is activated
    Qt Code:
    1. void MainWindow::readthetext(){
    2. ui->textEdit->setText("IT'S READY!");
    3. QString downloadedtext = http->readAll();
    4. ui->textEdit->setText(downloadedtext);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance

  5. #5
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    28
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problem with QHttp / HTML source download

    Qt Code:
    1. void readyRead ( const QHttpResponseHeader & resp )
    To copy to clipboard, switch view to plain text mode 

    Thats the signal. (You pass a QHttp object to that signal, that's why it does not work)

    This signal is useful if you want to process the data in chunks as soon as it becomes available. If you are only interested in the complete data, just connect to the requestFinished() signal and read the data then instead. I think this is the better way for your needs.

    But anyways you need to pass the "header" to your signal.

    This would be the correct solution:

    http://www.paste-code.com/paste.php?id=y8gPp5xaRS

    ( I haven't tested it but i guess it works. Anyways I would prefer the QNetworkAccessManager class to do that stuff. There are some examples how to use it in QtDemo)

Similar Threads

  1. How to limit download speed with QHttp ?
    By THRESHE in forum Qt Programming
    Replies: 6
    Last Post: 25th November 2010, 11:55
  2. Resume download with QHttp
    By THRESHE in forum Qt Programming
    Replies: 7
    Last Post: 17th April 2010, 10:12
  3. Download Source Code
    By psih128 in forum Newbie
    Replies: 3
    Last Post: 6th July 2009, 10:01
  4. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39
  5. QHTTP problem,download multi-file.
    By fengtian.we in forum Qt Programming
    Replies: 6
    Last Post: 28th May 2007, 06: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.