[Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

Henk te Sligte htesligte at gmail.com
Mon Apr 19 18:37:19 CEST 2010


That works! Thanks a lot!

(Weird part is that reply->waitForReadyRead() still returns false, but
I removed that part, and used reply->readAll(), which works like a
charm)

Greetings,
Henk te Sligte

2010/4/19 Scott Aron Bloom <Scott.Bloom at onshorecs.com>:
> Try this...
>
> After your get...
>
> Insert this
>
> QEventLoop eLoop;
> connect( nam, SIGNAL( finished( QNetworkReply * ) ), &eLoop, SLOT(
> quit() ) );
> eLoop.exec();
>
>
> You may want to do eLoop.exec(QEventLoop::ExcludeUserInputEvents )
>
> If your running a GUI and don't want "buttons getting clicked"
>
> Scott
>
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Henk te Sligte
> Sent: Monday, April 19, 2010 8:29 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] QNetworkAccessManager and QNetworkReply,
> synchronous
>
> 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