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. movetothread in threadpool
Qt 6.11 is out! See what's new in the release blog

movetothread in threadpool

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 6.7k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Are you trying to move a thread to another thread ?

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

    J 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Are you trying to move a thread to another thread ?

      J Offline
      J Offline
      JadeN001
      wrote on last edited by
      #3

      @SGaist i have corrected the question

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MokJ
        wrote on last edited by
        #4

        I'm not sure if we can specify the threads in threadpool, but I've just started to learn all this so...i'm not an expert.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          The idea behind QThreadPool is to use a QRunnable subclass object that does the job you want in another thread. You don't access the QThread objects used directly.

          So what are you trying to achieve ?

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

          J 1 Reply Last reply
          1
          • SGaistS SGaist

            The idea behind QThreadPool is to use a QRunnable subclass object that does the job you want in another thread. You don't access the QThread objects used directly.

            So what are you trying to achieve ?

            J Offline
            J Offline
            JadeN001
            wrote on last edited by
            #6

            @SGaist thank you.
            i want to use particular thread from Qthreadpool.
            for Ex:
            worker->moveToThread(mythread);

            here,as we are moving object in "mythread" same way i want to move object to the thread which is one of the Qthreadpool's thread.

            jsulmJ 1 Reply Last reply
            0
            • J JadeN001

              @SGaist thank you.
              i want to use particular thread from Qthreadpool.
              for Ex:
              worker->moveToThread(mythread);

              here,as we are moving object in "mythread" same way i want to move object to the thread which is one of the Qthreadpool's thread.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @JadeN001 said in movetothread in threadpool:

              i want to use particular thread from Qthreadpool.

              but why? Why do you care which thread from the pool is used?

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

              J 1 Reply Last reply
              1
              • jsulmJ jsulm

                @JadeN001 said in movetothread in threadpool:

                i want to use particular thread from Qthreadpool.

                but why? Why do you care which thread from the pool is used?

                J Offline
                J Offline
                JadeN001
                wrote on last edited by
                #8

                @jsulm i want to move two objects in one thread

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Why do you need two different objects moved to the same thread ?

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

                  J 1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #10

                    If you want to choose a specific thread to use, then create your own QThread. Don't use QThreadPool.

                    QThreadPool is designed for situations where you don't care which thread is being used.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    J 1 Reply Last reply
                    3
                    • M Offline
                      M Offline
                      MokJ
                      wrote on last edited by MokJ
                      #11

                      you can do

                      movetoThread(QThread::currentThread);
                      

                      in your runnable::run();

                      1 Reply Last reply
                      0
                      • JKSHJ JKSH

                        If you want to choose a specific thread to use, then create your own QThread. Don't use QThreadPool.

                        QThreadPool is designed for situations where you don't care which thread is being used.

                        J Offline
                        J Offline
                        JadeN001
                        wrote on last edited by
                        #12

                        @JKSH can i use
                        connect(socket, SIGNAL(readyRead()),this, SLOT(readyread()));
                        In run() of qrunnable class.

                        JKSHJ 1 Reply Last reply
                        0
                        • J JadeN001

                          @JKSH can i use
                          connect(socket, SIGNAL(readyRead()),this, SLOT(readyread()));
                          In run() of qrunnable class.

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #13

                          @JadeN001 said in movetothread in threadpool:

                          @JKSH can i use
                          connect(socket, SIGNAL(readyRead()),this, SLOT(readyread()));
                          In run() of qrunnable class.

                          I haven't done this before so I'm not 100% sure. It might be possible, but only if:

                          • Your QRunnable also runs its own event loop, AND
                          • You set your QRunnable's thread affinity correctly using QObject::moveToThread().

                          This feels messy/hacky to me though. Is there a reason why you don't want to use a worker QObject subclass plus a QThread instead?

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          J 1 Reply Last reply
                          0
                          • JKSHJ JKSH

                            @JadeN001 said in movetothread in threadpool:

                            @JKSH can i use
                            connect(socket, SIGNAL(readyRead()),this, SLOT(readyread()));
                            In run() of qrunnable class.

                            I haven't done this before so I'm not 100% sure. It might be possible, but only if:

                            • Your QRunnable also runs its own event loop, AND
                            • You set your QRunnable's thread affinity correctly using QObject::moveToThread().

                            This feels messy/hacky to me though. Is there a reason why you don't want to use a worker QObject subclass plus a QThread instead?

                            J Offline
                            J Offline
                            JadeN001
                            wrote on last edited by
                            #14

                            @JKSH i have already done my task using qthread.but i want make it possible by doing same thing using qthreadpool because in qthread i have made vector of limited threads.I think that it might me possible with qthreadpool.

                            As i know qrunnable doesnt have its own qeventloop.

                            You set your QRunnable's thread affinity correctly using QObject::moveToThread().
                            
                            

                            for this what i experiment is :
                            In run() of subclass QRunnable:

                            void run()
                            {
                               worker *w=new worker();
                                w->moveToThread(QThread::currentThread());
                                w->addclients(socketDescriptor);
                            }
                            

                            it is correct or not i don't know but it works.

                            1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Why do you need two different objects moved to the same thread ?

                              J Offline
                              J Offline
                              JadeN001
                              wrote on last edited by
                              #15

                              @SGaist
                              1.creating socket and store in o vector
                              2.Read the message from client
                              3.write that message to all clients.

                              these all task i want to do in SAME thread.
                              i have done that @mokj suggest me and it works.

                              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