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. Is it ok that QueuedConnection start every time a new copy of a function?
Forum Updated to NodeBB v4.3 + New Features

Is it ok that QueuedConnection start every time a new copy of a function?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 1.7k 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.
  • MikhailGM Offline
    MikhailGM Offline
    MikhailG
    wrote on last edited by MikhailG
    #1

    I have an issue or misunderstandig in understanding of how QueuedConnection and QThreads work. I have a controller class which contains a worker object that being moved to a QThread. From main I emit a signal to the controller class which emits signal (QueuedConnection) to the woker object to perform a particular task. In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object. But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?

    sierdzioS aha_1980A 2 Replies Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @MikhailG when a signal queueConnetion type is emited, this signal is inserted at end of queue to be processed when the event loop is able to deliver the signal to slot

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      0
      • MikhailGM MikhailG

        I have an issue or misunderstandig in understanding of how QueuedConnection and QThreads work. I have a controller class which contains a worker object that being moved to a QThread. From main I emit a signal to the controller class which emits signal (QueuedConnection) to the woker object to perform a particular task. In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object. But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        @MikhailG said in Is it ok that QueuedConnection start every time a new copy of a function?:

        In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object.

        This is a very bad idea. Worker object should never try to control event loop of the main thread. Either spin a local event loop to do the waiting, or simply exit the thread when your work is done. Your thread controller can start a new thread / job when it gets the signal to do some work.

        But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?

        Can you rephrase this question? I don't understand what you mean.

        If you mean that every signal emission emit causes your slot to execute, then that is exactly what should happen, normal behaviour.

        (Z(:^

        MikhailGM 1 Reply Last reply
        4
        • sierdzioS sierdzio

          @MikhailG said in Is it ok that QueuedConnection start every time a new copy of a function?:

          In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object.

          This is a very bad idea. Worker object should never try to control event loop of the main thread. Either spin a local event loop to do the waiting, or simply exit the thread when your work is done. Your thread controller can start a new thread / job when it gets the signal to do some work.

          But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?

          Can you rephrase this question? I don't understand what you mean.

          If you mean that every signal emission emit causes your slot to execute, then that is exactly what should happen, normal behaviour.

          MikhailGM Offline
          MikhailGM Offline
          MikhailG
          wrote on last edited by MikhailG
          #4

          @sierdzio said in Is it ok that QueuedConnection start every time a new copy of a function?:

          Can you rephrase this question? I don't understand what you mean.

          Well when I emit a signal to the worker object I pass a parameter for debugging purpose. Than I emit another signal with a debug data and I can see in logs for previous call and for current call debug data.

          //PrevCall data
          "D:/Music"
          "D:/Music"
          "D:/Music"
          "D:/Music"
          "D:/Music"
          "D:/Music"
          "D:/Music"
          AWESOME!
          //NewCall data
          "D:/ISO"
          "D:/ISO"
          "D:/ISO"
          "D:/ISO"
          "D:/ISO"
          "D:/ISO"
          //PrevCall data
          "D:/Music"
          "D:/Music"
          "D:/Music"
          "D:/Music"

          MikhailGM 1 Reply Last reply
          0
          • MikhailGM MikhailG

            @sierdzio said in Is it ok that QueuedConnection start every time a new copy of a function?:

            Can you rephrase this question? I don't understand what you mean.

            Well when I emit a signal to the worker object I pass a parameter for debugging purpose. Than I emit another signal with a debug data and I can see in logs for previous call and for current call debug data.

            //PrevCall data
            "D:/Music"
            "D:/Music"
            "D:/Music"
            "D:/Music"
            "D:/Music"
            "D:/Music"
            "D:/Music"
            AWESOME!
            //NewCall data
            "D:/ISO"
            "D:/ISO"
            "D:/ISO"
            "D:/ISO"
            "D:/ISO"
            "D:/ISO"
            //PrevCall data
            "D:/Music"
            "D:/Music"
            "D:/Music"
            "D:/Music"

            MikhailGM Offline
            MikhailGM Offline
            MikhailG
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • MikhailGM MikhailG

              I have an issue or misunderstandig in understanding of how QueuedConnection and QThreads work. I have a controller class which contains a worker object that being moved to a QThread. From main I emit a signal to the controller class which emits signal (QueuedConnection) to the woker object to perform a particular task. In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object. But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @MikhailG do you call connect multiple times for the same signal/slot?

              if so, that would lead to multiply slot calls for one emit

              Qt has to stay free or it will die.

              MikhailGM 1 Reply Last reply
              1
              • aha_1980A aha_1980

                @MikhailG do you call connect multiple times for the same signal/slot?

                if so, that would lead to multiply slot calls for one emit

                MikhailGM Offline
                MikhailGM Offline
                MikhailG
                wrote on last edited by
                #7

                @aha_1980 nope. One time

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

                  Hi,

                  Can you show your code ?

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

                  MikhailGM 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    Hi,

                    Can you show your code ?

                    MikhailGM Offline
                    MikhailGM Offline
                    MikhailG
                    wrote on last edited by MikhailG
                    #9

                    @SGaist I got an answer. Thank you.

                    aha_1980A 1 Reply Last reply
                    0
                    • MikhailGM MikhailG

                      @SGaist I got an answer. Thank you.

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @MikhailG can you share your solution?

                      Qt has to stay free or it will die.

                      MikhailGM 1 Reply Last reply
                      0
                      • aha_1980A aha_1980

                        @MikhailG can you share your solution?

                        MikhailGM Offline
                        MikhailGM Offline
                        MikhailG
                        wrote on last edited by
                        #11

                        @aha_1980 sure here I got all the answers. And I decided to read a book Summerfiled qt4 professional programming.

                        1 Reply Last reply
                        1

                        • Login

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