Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QNetworkManager : resend qnetworkrequest before end make it crash

QNetworkManager : resend qnetworkrequest before end make it crash

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qnetworkrequestqeventloop
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrDiv
    wrote on 8 Mar 2016, 15:08 last edited by
    #1

    Hey,

    I'm working on an embedded buying application. When the customer add a product to his cart, i send a QNetworkRequest with a webservice as URL to update the backoffice. But if the customer double click the add-to-cart button, i think that the request is resend before the end of the first and make the application exit with error : "QEventLoop::exec: instance 0x423190 has already called exec()".

    Here is my doRequest function :

    const QString&                            Request::doRequest(const QString& request, RequestType type, const QByteArray& data)
    {
        QObject::connect(&_networkManager, SIGNAL(finished(QNetworkReply*)), &_eventLoop, SLOT(quit()));
        QUrl url(request);
        QNetworkRequest req(url);
    
        switch (type)
        {
        case e_GET :
            _reply = _networkManager.get(req);
            break;
        case e_POST :
            _reply = _networkManager.post(req, data);
            break;
        case e_PUT :
            _reply = _networkManager.put(req, data);
            break;
        case e_DELETE :
            _reply = _networkManager.deleteResource(req);
            break;
        }
        _eventLoop.exec();
        if (_reply->error() == QNetworkReply::NoError)
            {
                QString result = _reply->readAll();
                delete _reply;
                return (result);
            }
        delete _reply;
        return ("");
    }
    

    Does anyone encounter the same problem ? Is there a work around?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrDiv
      wrote on 8 Mar 2016, 15:35 last edited by
      #2

      One possible solution is to launch one thread for each request

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 8 Mar 2016, 22:13 last edited by
        #3

        Hi and welcome to devnet,

        That's because you are calling exec on _eventLoop twice. You should rather use a local QEventLoop or not allow the query to start if already in progress.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        3/3

        8 Mar 2016, 22:13

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved