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. How do you wait for multiple signals?
Forum Updated to NodeBB v4.3 + New Features

How do you wait for multiple signals?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 6 Posters 747 Views 3 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.
  • A Offline
    A Offline
    AntonioFinn
    wrote on last edited by AntonioFinn
    #1

    I need to make multiple http request in parallel (using QNetworkaAcessManager) and continue the program only after all the requests have finished.

    One possible solution would be to keep track of the total number of requests and the current number of finished request, when the finished() signal is sent increment currentFinishedRequests by one, if it's equal to totalNumberOfRequests it means all the requests have finished (we could send another signal to continue the program or call a function).
    I found this solution a bit ulgy, is there a better way to do it? https://showbox.bio/ https://tutuapp.uno/ https://vidmate.cool/

    Pablo J. RoginaP kshegunovK J.HilkJ 3 Replies Last reply
    0
    • A AntonioFinn

      I need to make multiple http request in parallel (using QNetworkaAcessManager) and continue the program only after all the requests have finished.

      One possible solution would be to keep track of the total number of requests and the current number of finished request, when the finished() signal is sent increment currentFinishedRequests by one, if it's equal to totalNumberOfRequests it means all the requests have finished (we could send another signal to continue the program or call a function).
      I found this solution a bit ulgy, is there a better way to do it? https://showbox.bio/ https://tutuapp.uno/ https://vidmate.cool/

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @AntonioFinn

      Please keep in mind that QNetworkAccessManager has a limitation on the number of parallel requests. From documentation:

      Note: QNetworkAccessManager queues the requests it receives. The number of requests executed in parallel is dependent on the protocol. Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      5
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #3

        The direct answer to your question seems trivial....Ummm maybe a counter that increases and st checked every time the slot code is executed?

        Guess I should have completely read the OP...That's the way I'd do it.

        1 Reply Last reply
        0
        • gde23G Offline
          gde23G Offline
          gde23
          wrote on last edited by
          #4

          Since the time each request takes to be finished is different for each request and therefore the order is kind of random as a matter of principle you never know if the request that finished is the last one. Therefore there is no way around to wait for all the finish signals to arrive. And as you already suggested the easiest implementation is counting them. Just make sure to use an atomic to avoid race conditions for the counter.

          Kent-DorfmanK 1 Reply Last reply
          0
          • gde23G gde23

            Since the time each request takes to be finished is different for each request and therefore the order is kind of random as a matter of principle you never know if the request that finished is the last one. Therefore there is no way around to wait for all the finish signals to arrive. And as you already suggested the easiest implementation is counting them. Just make sure to use an atomic to avoid race conditions for the counter.

            Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by
            #5

            @gde23 said in How do you wait for multiple signals?:

            Just make sure to use an atomic to avoid race conditions for the counter.

            Is that really necessary? Are the slots truly executed concurrently?

            1 Reply Last reply
            2
            • A AntonioFinn

              I need to make multiple http request in parallel (using QNetworkaAcessManager) and continue the program only after all the requests have finished.

              One possible solution would be to keep track of the total number of requests and the current number of finished request, when the finished() signal is sent increment currentFinishedRequests by one, if it's equal to totalNumberOfRequests it means all the requests have finished (we could send another signal to continue the program or call a function).
              I found this solution a bit ulgy, is there a better way to do it? https://showbox.bio/ https://tutuapp.uno/ https://vidmate.cool/

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @AntonioFinn said in How do you wait for multiple signals?:

              One possible solution would be to keep track of the total number of requests and the current number of finished request, when the finished() signal is sent increment currentFinishedRequests by one, if it's equal to totalNumberOfRequests it means all the requests have finished (we could send another signal to continue the program or call a function).
              I found this solution a bit ulgy, is there a better way to do it?

              Well, it is ugly, sort of, but it's a proper one. That's how I'd do it, although I'd encapsulate the implementation in a separate class (a QObject subclass) with a nice to use API.

              @Kent-Dorfman said in How do you wait for multiple signals?:

              Just make sure to use an atomic to avoid race conditions for the counter.

              Is that really necessary?

              Almost certainly not.

              Are the slots truly executed concurrently?

              Not unless you specifically do so manually (i.e. force Qt::DirectConnection)

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              5
              • A AntonioFinn

                I need to make multiple http request in parallel (using QNetworkaAcessManager) and continue the program only after all the requests have finished.

                One possible solution would be to keep track of the total number of requests and the current number of finished request, when the finished() signal is sent increment currentFinishedRequests by one, if it's equal to totalNumberOfRequests it means all the requests have finished (we could send another signal to continue the program or call a function).
                I found this solution a bit ulgy, is there a better way to do it? https://showbox.bio/ https://tutuapp.uno/ https://vidmate.cool/

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @AntonioFinn said in How do you wait for multiple signals?:

                I found this solution a bit ulgy, is there a better way to do it?

                I would actually store pointers to the QNetworkReply
                the finished signal points to the same reply that you get a pointer to when you make your get request. And you have to delete it manually anyway and you know exactly what request finished when🤷‍♂️


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                4

                • Login

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