[Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

Jason H scorp1us at yahoo.com
Mon Apr 19 23:19:12 CEST 2010


I never got the original message for this thread....

But libqxt has a QxtSignalWaiter class.

I'd love Qt to have a blocking static method, but they refuse. (For some good reasons) but if you are in your own thread (not the GUI)  and you are synchronous, then a blocking call should work. Of course, Qt allows you to not use more than one thread when doing i/o in an orderly manner which is what the Trolls seem to prefer.





----- Original Message ----
From: Henk te Sligte <htesligte at gmail.com>
Cc: qt-interest at trolltech.com
Sent: Mon, April 19, 2010 12:40:10 PM
Subject: Re: [Qt-interest] QNetworkAccessManager and QNetworkReply, synchronous

Oh, as J-P Nurmi already said, waitForReadyRead just doesn't work. I couldn't
figure it out from the documentation, that just said some functions
where inherited from QIODevice. I figured this was one of them. I'm
wrong, I guess :)

Greetings,
Henk te Sligte

2010/4/19 Henk te Sligte <htesligte at gmail.com>:
> 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
>>
>

_______________________________________________
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