QNetworkReply



  • I am trying to send message through IP modem
    The given code sends the message successfully but the modem receives it 3 times. Is there anything wrong the code?
    I think the loop is executing 3 times!
    When I used the URL directly in browser it gives the message ID as reply
    Here in code I am not getting anything.
    Pls see my code and suggest me to do modification

    @
    QUrl myURL("http://31.103.3.167:81/sendmsg?user=admin&passwd=admin&cat=1&to=9869XXXXXX&text=hello");
    QNetworkRequest myRequest(myURL);
    QNetworkAccessManager myManager(this);
    QNetworkReply *reply=myManager.get(myRequest);
    QEventLoop loop;
    connect(reply,SIGNAL(finished()),&loop,SLOT(quit()));
    QByteArray byteData = reply->readAll();
    QString stringData(byteData);
    delete reply;
    @



  • "This example how to send a HTTP request and how to handle the response":http://developer.qt.nokia.com/wiki/Download_Data_from_URL might be useful to solve your problem.



  • i think you forgot loop.exec() before the readAll(). so You create the event loop, but it is not running so it immediately executes the readAll() which will mostly return an empty byte array



  • I tried with loop.exec() also
    buth the problem is ,in the modem i am getting the message 3 times for one execution of the code
    is the loop.exec() is executing thrice
    by copying the same URL in to the browser i am getting the reply as message ID
    like "ID=23"

    @
    QUrl myURL("http://31.103.3.167:81/sendmsg?user=admin&passwd=admin&cat=1&to=9869XXXXXX&text=hello");
    QNetworkRequest myRequest(myURL);
    QNetworkAccessManager myManager(this);
    QNetworkReply *reply=myManager.get(myRequest);
    QEventLoop loop;
    connect(reply,SIGNAL(finished()),&loop,SLOT(quit()));
    loop.exec();
    QByteArray byteData = reply->readAll();
    QString stringData(byteData); delete reply;
    @



  • The request is sent only once. Are you on a mobile platform? It may be that the underlying system tries to send the message through different means of transport (WiFi, mobile netowork...)



  • Thanks for reply
    It is not on WIFI,Mobile , I am developing in Desktop only
    i replaced the loop with minimum code ie
    @
    QUrl myURL("http://31.103.3.167:81/sendmsg?user=admin&passwd=admin&cat=1&to=9869XXXXXX&text=hello");
    QNetworkRequest myRequest(myURL);
    QNetworkAccessManager myManager(this)
    myManager.get(myRequest);
    exec();
    @
    then also it sends the message three times.
    can u tell me how can debug ...so that i should know, how many times it is sending to the IP Modem
    I also tried to debug the exec() but it gives "true " only one time.it means that it is executing only once. Is there any other method to send request to IPModem just give me some hint ,i will try



  • Something additional must be odd in your application.

    A short, yet complete, compilable test case would bring more light into this mysterious case. With the snippets you've given, there's nothing more to say than that it should work.


Log in to reply