[Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

Scott Aron Bloom Scott.Bloom at onshorecs.com
Mon Apr 19 17:54:26 CEST 2010


You have to run the event loop....

Scott

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Benjamin Lau
Sent: Monday, April 19, 2010 8:47 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QNetworkAccessManager and QNetworkReply,synchronous

You'll have to busy-wait if you want to implement "blocking" access.

What you do is in a loop, check repeatedly for reply->isFinished() .
When it is true, break from the loop. After each check, sleep for a
time interval, say 0.5 secs.

So something like this:

while(!reply->isFinished())
    Sleep(0.5);

On Mon, Apr 19, 2010 at 11: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
>

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list