[Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

J-P Nurmi jpnurmi at gmail.com
Mon Apr 19 17:39:55 CEST 2010


On Mon, Apr 19, 2010 at 6:28 PM, Henk te Sligte <htesligte at gmail.com> wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>

Hi,

As far as I remember, QIODevice::waitForReadyRead() does nothing.
Furthermore, QNetworkReply(Impl) does not reimplement it.

--
J-P Nurmi




More information about the Qt-interest-old mailing list