PDA

View Full Version : QHTTP Readall() function



nbkhwjm
17th April 2007, 00:37
I am attempting to use the following function to read a plain text file from a webserver to populate a simple text string of the version number. The web file only has "0.1" in it. It will be the version number. This will eventually be an automatic version check, but i cannot seem to get the QHTTP readall() function to work.

I can see that the connection to the webserver is made (via wireshark) and the proper file is accessed, but the contents are never place in the "version" variable.

no errors are generated from this, only "Automatic Version Check" is written to Debug and ui.statusLogs is updated with "Version is:" no Version number from http though..

here is the function.


void Porcupine::checkVersion()
{
qDebug("Automatic Version Check");

versionHttp = new QHttp();
versionHttp->setHost("192.168.1.111", 80);
versionHttp->get("/version.txt");

QString version = versionHttp->readAll();

ui.statusLogs->append(tr("Version is: %1")
.arg(version));
}



Thanks.

jacek
17th April 2007, 00:41
QHttp needs time to fetch the result --- it will emit a signal when the result is available and only then you can read it.

nbkhwjm
17th April 2007, 00:55
Great This worked



void Porcupine::checkVersion()
{
qDebug("Automatic Version Check");

versionHttp = new QHttp();

connect(versionHttp, SIGNAL(done(bool)), this, SLOT(showVersion()));

versionHttp->setHost("192.168.1.111", 80);
versionHttp->get("/version.txt");

}

void Porcupine::showVersion()
{
QString version = versionHttp->readAll();

ui.statusLogs->append(tr("Version is: %1")
.arg(version));
}