PDA

View Full Version : QHttp signals don't work !!



probine
11th January 2007, 13:56
I have a QHttp object.



http = new QHttp("http://localhost", 80);
http->get("http://localhost/easyadvice/images/logo.jpg", 0);
.
.
.
connect(http, SIGNAL(readyRead()), this, SLOT(read()));


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

What is wrong ?

jacek
11th January 2007, 13:59
What is wrong ?
There is no such signal, try:
connect( http, SIGNAL( readyRead( const QHttpResponseHeader & ) ), this, SLOT( read() ) );

probine
11th January 2007, 14:07
The code:



http = new QHttp("http://localhost", 80);
http->get("http://localhost/easyadvice/images/logo.jpg", 0);
connect(http, SIGNAL(requestFinished( const QHttpResponseHeader & )), this, SLOT(readLogo()));
.
.
.
void ChatUi::readLogo(){
QString logo = http->readAll();
tbLogo->append(logo);
}


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

Am I missing something else in the code ?

jpn
11th January 2007, 14:31
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().

Cesar
11th January 2007, 14:33
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.
Make sure readLogo() is defined as a slot in your header file.
Make sure your file gets parsed by MOC.
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

probine
11th January 2007, 14:38
I was using QHttp::requestFinished(int id, bool error)

Look at the code



connect(http, SIGNAL(requestFinished(int id, bool error)), this, SLOT(readLogo(int id, bool error)));



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

Please help !

probine
11th January 2007, 14:44
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 ?

camel
11th January 2007, 14:44
The code:



void ChatUi::readLogo(){
QString logo = http->readAll();
tbLogo->append(logo);
}



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 (http://doc.trolltech.com/4.2/qstring.html#QString-8) 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 (http://doc.trolltech.com/4.2/qimage.html#fromData-2) to actually transform that character data into a usable image. Which you then can (somehow) append to the textbrowser...

camel
11th January 2007, 14:45
connect(http, SIGNAL(requestFinished(int id, bool error)), this, SLOT(readLogo(int id, bool error)));



No variable names in SIGNAL or SLOT macros.

camel
11th January 2007, 14:50
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?


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.

probine
11th January 2007, 14:51
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.



void ChatUi::readLogo(const QHttpResponseHeader &){
tbLogo->append("<html><table><tr><td>hi</td></tr></table></html>");
}


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

camel
11th January 2007, 15:02
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 (http://doc.trolltech.com/4.2/qhttp.html#requestStarted) signal.


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