Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager never sends request
Qt 6.11 is out! See what's new in the release blog

QNetworkAccessManager never sends request

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    izzy.coding
    wrote on last edited by
    #1

    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);
    

    }
    @

    Every line of code is an error waiting to happen

    1 Reply Last reply
    0
    • I Offline
      I Offline
      izzy.coding
      wrote on last edited by
      #2

      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.

      Every line of code is an error waiting to happen

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #3

        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.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        1 Reply Last reply
        0
        • I Offline
          I Offline
          izzy.coding
          wrote on last edited by
          #4

          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,

          Every line of code is an error waiting to happen

          1 Reply Last reply
          0

          • Login

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