Home > Mobile >  Questions about the QNetworkAccessManager get repeat send message
Questions about the QNetworkAccessManager get repeat send message

Time:10-14

Call use QNetworkAccessManager the get method, caught while on a repeat sent two times the same request, who know how to return a responsibility?


# test code
 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include


Int main (int arg c, char * argv [])
{
QCoreApplication a (arg c, argv);


QNetworkAccessManager accessManager;
QNetworkRequest request;
//QUrl url (" http://192.168.1.170 ");
QUrl url (" http://root:[email protected]/cgi-bin/UVSSapi.cgi? {\ "CMD " : \ "get ", \ "key " : \ "server IP "} ");
Request. The setUrl (url);

QNetworkReply * reply=accessManager. Get (request);//by sending data, the return value stored in the pointer to the reply.

QTimer _timer;
The QEventLoop _event_loop;
QObject: : connect (& amp; _timer, SIGNAL (timeout ()), & amp; _event_loop, SLOT (the quit ()));
QObject: : connect (& amp; AccessManager, SIGNAL (finished (QNetworkReply *)), & amp; _event_loop, SLOT (the quit ()));
_timer. SetSingleShot (true);
_timer. Start (5 * 1000);
_event_loop. The exec ();

QByteArray response=reply - & gt; ReadAll ();
QDebug () & lt; & lt;" The response "& lt;

Return a.e xec ();
}

  •  Tags:  
  • Qt
  • Related