Results 1 to 12 of 12

Thread: QHttp signals don't work !!

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QHttp signals don't work !!

    I have a QHttp object.

    Qt Code:
    1. http = new QHttp("http://localhost", 80);
    2. http->get("http://localhost/easyadvice/images/logo.jpg", 0);
    3. .
    4. .
    5. .
    6. connect(http, SIGNAL(readyRead()), this, SLOT(read()));
    To copy to clipboard, switch view to plain text mode 

    The console prints this message:
    Object::connect: No such signal QHttp::readyRead()

    What is wrong ?

  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 signals don't work !!

    Quote Originally Posted by probine View Post
    What is wrong ?
    There is no such signal, try:
    Qt Code:
    1. connect( http, SIGNAL( readyRead( const QHttpResponseHeader & ) ), this, SLOT( read() ) );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    The code:

    Qt Code:
    1. http = new QHttp("http://localhost", 80);
    2. http->get("http://localhost/easyadvice/images/logo.jpg", 0);
    3. connect(http, SIGNAL(requestFinished( const QHttpResponseHeader & )), this, SLOT(readLogo()));
    4. .
    5. .
    6. .
    7. void ChatUi::readLogo(){
    8. QString logo = http->readAll();
    9. tbLogo->append(logo);
    10. }
    To copy to clipboard, switch view to plain text mode 

    It should append the logo to the QTextBrowser, why it is not there ?

    Am I missing something else in the code ?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHttp signals don't work !!

    QHttp::readyRead(const QHttpResponseHeader&):
    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.
    So try using signal QHttp::requestFinished(int id, bool error) instead of readyRead().
    J-P Nurmi

  5. #5
    Join Date
    Feb 2006
    Location
    Kirovohrad, Ukraine
    Posts
    72
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    1. Make sure your connection establishes. Try to launch in debug mode with CONFIG += console (if you are on Windows). Make sure it doesn't report signal-slot connection problems.
    2. Make sure readLogo() is defined as a slot in your header file.
    3. Make sure your file gets parsed by MOC.
    4. I'd suggest you to redesign you readLogo() to readLogo(const QHttpResponseHeader &). Inside of it you'd better check whether header.statusCode() == 200, which means successful reply.


    WBR, Cesar

  6. #6
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    I was using QHttp::requestFinished(int id, bool error)

    Look at the code
    Qt Code:
    1. connect(http, SIGNAL(requestFinished(int id, bool error)), this, SLOT(readLogo(int id, bool error)));
    To copy to clipboard, switch view to plain text mode 

    This is the console message:
    Object::connect: No such signal QHttp::requestFinished(int id,bool error)

    Please help !

  7. #7
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    My program is working, so I added a tbLogo->append("hi"); to see if I even get here, but I don't.

    Probably I am never even sending the request to the server.

    What am I missing ?

  8. #8
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    Quote Originally Posted by probine View Post
    The code:

    Qt Code:
    1. void ChatUi::readLogo(){
    2. QString logo = http->readAll();
    3. tbLogo->append(logo);
    4. }
    To copy to clipboard, switch view to plain text mode 
    What you are doing here is reading the character data that is returned from the webserver. (At this point a QByteArray), and let Qt handle the transformation to a QString.

    1) Handling binary data as ascii and transforming it to unicode (QString) is a bad idea, and probably not what you wanted.

    2) You append this weirdly transformed piece of data to the textbrowser...



    You will probably need to use some qimage function to actually transform that character data into a usable image. Which you then can (somehow) append to the textbrowser...

  9. #9
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    Quote Originally Posted by probine View Post
    Qt Code:
    1. connect(http, SIGNAL(requestFinished(int id, bool error)), this, SLOT(readLogo(int id, bool error)));
    To copy to clipboard, switch view to plain text mode 
    No variable names in SIGNAL or SLOT macros.

  10. #10
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    Quote Originally Posted by probine View Post
    My program is working, so I added a tbLogo->append("hi"); to see if I even get here, but I don't.
    So by work, you mean compile?

    Quote Originally Posted by probine View Post
    Probably I am never even sending the request to the server.
    If the webserver is really running locally, you can very easily check that by checking the access logs of said server, otherwise its very hard to say.

  11. #11
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    Let's go one step back.

    I am not even getting to the readLogo() function, I know it because the following function never prints anything in the QTextBrowser.

    Qt Code:
    1. void ChatUi::readLogo(const QHttpResponseHeader &){
    2. tbLogo->append("<html><table><tr><td>hi</td></tr></table></html>");
    3. }
    To copy to clipboard, switch view to plain text mode 

    I guess I am not even sending the request, then please help me solving this issue first.

  12. #12
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp signals don't work !!

    Quote Originally Posted by probine View Post
    I guess I am not even sending the request, then please help me solving this issue first.
    Are you starting the request? (Some qDebug output can do wonders)

    Is your webserver logging some access?

    Is there any warning output regarding signals not connected?

    You might want to see if you get the requestStarted signal.


    If nothing works, post a minimal compilable example...

Similar Threads

  1. Combobox Signals
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2006, 10:21
  2. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  3. QHttp related
    By whoops.slo in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2006, 20:57
  4. Signals destroys my pointer
    By Jojo in forum Qt Programming
    Replies: 12
    Last Post: 7th March 2006, 21:05
  5. KDE Signals
    By chombium in forum KDE Forum
    Replies: 1
    Last Post: 25th January 2006, 18:45

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.