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. Qthread and child thread communication between other thread
QtWS25 Last Chance

Qthread and child thread communication between other thread

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 6 Posters 2.0k Views
  • 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.
  • R Offline
    R Offline
    RahibeMeryem
    wrote on 29 Jan 2019, 17:19 last edited by
    #1

    Hi,

    I am creating threads in mainGUI thread with

        cam_01_thread = new QThread;
        cam_01 = new Camera01;
        cam_01->moveToThread(cam_01_thread);
    
        cam_02_thread = new QThread;
        cam_02 = new Camera_02;
        cam_02->moveToThread(cam_02_thread);
    
        frameProcess_thread = new QThread;
        process = new Camera_03;
        process->moveToThread(frameProcess_thread);
    

    all can ben communicate with mainGUI thats okey.

    I just wonder Can I use signal slot mechanism between these three threads ?

    such as cam1 and cam2 thread sends Region of isterest to the Process frame and process frame decide to whether send to mainGUI or not ?

    Or I can only communicate with the mainGui thread

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 29 Jan 2019, 17:24 last edited by
      #2

      You can use signals and slots between worker threads as well.

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

      1 Reply Last reply
      4
      • R Offline
        R Offline
        RahibeMeryem
        wrote on 29 Jan 2019, 19:18 last edited by RahibeMeryem
        #3

        @dheerendra
        All three thread created by mainGUI thread.

        So can we connect between these workers thread ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Jan 2019, 20:36 last edited by
          #4

          Hi,

          Yes you can connect objects belonging to different threads.

          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
          • R Offline
            R Offline
            RahibeMeryem
            wrote on 29 Jan 2019, 20:38 last edited by
            #5

            @dheerendra
            @SGaist

            may I ask a simple example ?

            :)(:

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 29 Jan 2019, 20:45 last edited by
              #6

              You have one in QThread's documentation.

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

              R 1 Reply Last reply 30 Jan 2019, 11:20
              3
              • S SGaist
                29 Jan 2019, 20:45

                You have one in QThread's documentation.

                R Offline
                R Offline
                RahibeMeryem
                wrote on 30 Jan 2019, 11:20 last edited by
                #7

                @SGaist

                I saw the example the thread created in the same class that going to be signal/slot used.

                Here the all three thread created in mainGUI inthat case how can I connect between these worker thread (signal/slot) or do I need to connectted only from mainGUI thread as broker ?

                I didnt see an example that same scenario as above?
                Best

                J J 2 Replies Last reply 30 Jan 2019, 11:28
                0
                • R RahibeMeryem
                  30 Jan 2019, 11:20

                  @SGaist

                  I saw the example the thread created in the same class that going to be signal/slot used.

                  Here the all three thread created in mainGUI inthat case how can I connect between these worker thread (signal/slot) or do I need to connectted only from mainGUI thread as broker ?

                  I didnt see an example that same scenario as above?
                  Best

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 30 Jan 2019, 11:28 last edited by jsulm
                  #8

                  @RahibeMeryem

                  cam_01_thread = new QThread;
                      cam_01 = new Camera01;
                      cam_01->moveToThread(cam_01_thread);
                  
                      cam_02_thread = new QThread;
                      cam_02 = new Camera_02;
                      cam_02->moveToThread(cam_02_thread);
                  
                      frameProcess_thread = new QThread;
                      process = new Camera_03;
                      process->moveToThread(frameProcess_thread);
                  connect(cam_01, &Camera01::signal, cam_02, Camera_02::slot, Qt::QueuedConnection);
                  

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

                  1 Reply Last reply
                  3
                  • R RahibeMeryem
                    30 Jan 2019, 11:20

                    @SGaist

                    I saw the example the thread created in the same class that going to be signal/slot used.

                    Here the all three thread created in mainGUI inthat case how can I connect between these worker thread (signal/slot) or do I need to connectted only from mainGUI thread as broker ?

                    I didnt see an example that same scenario as above?
                    Best

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 30 Jan 2019, 11:29 last edited by J.Hilk
                    #9

                    @RahibeMeryem
                    nothing changes, really.

                    make your connect inside the main Thread - where you create the different threads & workes - because that class has acess the all your instances.

                    connect singal from worker 1 to slot of worker 2 and do the connect inside the main class/thread


                    jsulm was a bit faster ;-)

                    don't forget to subsditute signal and slot with actual signals&slots of your classes.


                    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
                    3
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 30 Jan 2019, 11:36 last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        RahibeMeryem
                        wrote on 30 Jan 2019, 12:09 last edited by
                        #11

                        cant believe so simple..

                        need to refresh my coffee.

                        thanks a lot all dear friends.

                        1 Reply Last reply
                        0

                        3/11

                        29 Jan 2019, 19:18

                        topic:navigator.unread, 8
                        • Login

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