[Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

Henk te Sligte htesligte at gmail.com
Mon Apr 19 17:28:54 CEST 2010


Guys, I really hope someone can help me out here. I'm trying to do a
synchronous network request. My application needs to wait before there
is data available. But, I can't figure out how to do it without QHttp.

This is what I'm having (nam is a private member, a QNetworkAccessManager):
QString MyClass::getVersionInfo() {
    QString uri = "http://geensite.nl/test.php";
    qDebug("Starting");
    qDebug(uri.toAscii());
    QNetworkRequest request;
    request.setUrl(QUrl(uri));
    QNetworkReply *reply = nam->get(request);
    qDebug("Request started");
    if(reply->waitForReadyRead(-1)) {
        qDebug("It works!");
        QByteArray data = reply->readAll();
        QString req(data);
        return req;
    } else {
        qDebug("There must be an error");
        return reply->errorString();
    }
}

It should obviously return the data from the http page, which is just
a simple php script, doing a mysql query and an echo. So I figured
this function should return "Everything works!", the output of the
echo. Well, it doesn't. It only returns "Unknown error". The web page
is visited, according to my logs, by this application, but I don't get
the output. Can anyone please help me out? I got lost in these signals
and slots, and couldn't figure out a way to do it synchronously with
signals. So any help is really appreciated. Thanks a lot in advance.

Greetings,
Henk te Sligte



More information about the Qt-interest-old mailing list