QNetworkAccessManager never sends request



  • I am writing an application where I need to call a web service to get initialisation data.
    In my app I have got a splash screen with a new thread for executing my initialisation code.
    This is all surrounded by an event loop so seems to work fine. However in my new thread When I try to make a call to my service I get nothing and it just sits there indefinitely. I can step through and see the request being created. this is then passed int the QNetworkAccessManager's get function. I then connect up all the signals and slots.
    However nothing is being sent and none of the slots are triggered.
    Am I missing something simple here?

    Here is a rough example of what my request function is doing:
    @
    void httpRequest::getRequest(QUrl& url)
    {
    if (_response) { return; }

    _responseError = false;
    createRequest(url);
    _response = _webCtrl.get(*_request);
    connect(_response,
            (void (QNetworkReply::*)(QNetworkReply::NetworkError))&QNetworkReply::error,
            this,
            &httpRequest::errorOccurred);
    connect(_response,
            &QNetworkReply::finished,
            this,
            &httpRequest::netRequestComplete);
    

    }
    @



  • Hey,

    I have not exactly solved my issue but have worked around it. I have now removed all processing threads and put all my QNetwork... code into the slashScreen. This seems to have fixed it as the requests are now actually going and I am getting all the slots triggered.
    Still unsure why this exact same code did not work through another thread.



  • Which thread created request ? Is it worker thread or main thread. If it is worker thread, try creating in worker thread. It may be something to with ownership of NetworkManager object.



  • Hi,
    Yes, I have a wrapper class that creates the QNetworkAccessManager and all of the request objects. This class is instanced in the run method of a QRunnable in a pointer with all signals and slots connected.
    I can see the request being created but none of the slots ever get called.
    If I call the exact same code from within the main thread it all works fine.
    Will try and put together an example project showing this and post it later.
    Regards,


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.