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 to correctly Connect from qthreadpool
Forum Updated to NodeBB v4.3 + New Features

How to correctly Connect from qthreadpool

Scheduled Pinned Locked Moved Unsolved General and Desktop
qthreadpoolsignalslots
11 Posts 3 Posters 1.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.
  • P Offline
    P Offline
    PXLFuSSeL
    wrote on 12 Jan 2021, 13:50 last edited by
    #1

    Hello,

    I develop a small program, where i add in a Loop multiple small Tasks to a Threads.
    If the Work ist done i want to add a Line to a qlist.
    But how did i correctly Connect that Tasks to emit the Signal? Or is there a way to Check from qthreadpool when the Task ist finished?

    Greetz from germany

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Jan 2021, 18:03 last edited by
      #2

      Hi,

      Do you mean from your QRunnable subclass ?

      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
      1
      • P Offline
        P Offline
        PXLFuSSeL
        wrote on 12 Jan 2021, 19:31 last edited by PXLFuSSeL 1 Dec 2021, 19:35
        #3

        Hy,
        thats what i mean.

        i have implemented a QRunnable to do that work.
        Then i loop through a list were the params in, create an object, connect the signal and slot, and start the work with pool->start().

        But all i get is "Function recv() failed" on console but no entrie in my list.
        Is that correct? Or shall i implement an own kind of threadpool?

        regards,

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jan 2021, 19:35 last edited by
          #4

          Since you have a list of parameters that you iterate, why not use QtConcurrent::map and QFutureWatcher ?

          You'll have the progress indication for free.

          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
          2
          • P Offline
            P Offline
            PXLFuSSeL
            wrote on 12 Jan 2021, 19:51 last edited by
            #5

            I know Threadpools from python and thought it works the same way.
            But ok i will give that a shot.

            QImage scaled(const QImage &image)
            {
            return image.scaled(100, 100);
            }

            QList<QImage> images = ...;
            QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled);

            like that?

            Thx

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Jan 2021, 20:06 last edited by
              #6

              Yes, adding a QFutureWatcher in the mix.

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

              P 1 Reply Last reply 1 Feb 2021, 23:25
              2
              • S SGaist
                12 Jan 2021, 20:06

                Yes, adding a QFutureWatcher in the mix.

                P Offline
                P Offline
                PXLFuSSeL
                wrote on 1 Feb 2021, 23:25 last edited by
                #7

                @SGaist
                hey is there also a way to get the already compute results while running?
                So i want to update the gui, as soon as an results is computed.
                Or isnt it a good idea?

                J 1 Reply Last reply 2 Feb 2021, 05:38
                0
                • P PXLFuSSeL
                  1 Feb 2021, 23:25

                  @SGaist
                  hey is there also a way to get the already compute results while running?
                  So i want to update the gui, as soon as an results is computed.
                  Or isnt it a good idea?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 2 Feb 2021, 05:38 last edited by
                  #8

                  @PXLFuSSeL You get the result from QFuture and then update the GUI. Using QFutureWatcher (as @SGaist suggested) you also get notification when a job is finished and then use QFuture to get the result.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  P 1 Reply Last reply 5 Feb 2021, 21:08
                  3
                  • J jsulm
                    2 Feb 2021, 05:38

                    @PXLFuSSeL You get the result from QFuture and then update the GUI. Using QFutureWatcher (as @SGaist suggested) you also get notification when a job is finished and then use QFuture to get the result.

                    P Offline
                    P Offline
                    PXLFuSSeL
                    wrote on 5 Feb 2021, 21:08 last edited by
                    #9

                    @jsulm yes that is implemented, but i am interested in getting a result as soon as it is calculated, because am working with really big lists

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 5 Feb 2021, 22:22 last edited by
                      #10

                      As already hinted twice, QFutureWatcher is your friend.

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

                      P 1 Reply Last reply 5 Feb 2021, 22:25
                      0
                      • S SGaist
                        5 Feb 2021, 22:22

                        As already hinted twice, QFutureWatcher is your friend.

                        P Offline
                        P Offline
                        PXLFuSSeL
                        wrote on 5 Feb 2021, 22:25 last edited by
                        #11

                        @SGaist yes, thx, my fault was trying to iterate through the future until not be ready.
                        now i got what i want, not as fast as i want, but it works stable.

                        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