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. Emitting signal from the same slot it is connected to.
Forum Updated to NodeBB v4.3 + New Features

Emitting signal from the same slot it is connected to.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 383 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.
  • C Offline
    C Offline
    candidaj
    wrote on last edited by
    #1

    Can i emit the signal which slot is connected from the same slot again. I will make the emit from slot conditional and happen only once,to avoid recursive calling.Can this lead to an issue?

    I'm working with a Qt application involving signals and slots. A signal is emitted from a state machine running in a separate thread, initiated by a function in Class A. After the state machine completes, it emits a signal connected to a slot in Class B. In the slot execution, I'm calling the same function to run the state machine again. Could this approach potentially cause issues?

    jsulmJ JonBJ 2 Replies Last reply
    0
    • C candidaj

      Can i emit the signal which slot is connected from the same slot again. I will make the emit from slot conditional and happen only once,to avoid recursive calling.Can this lead to an issue?

      I'm working with a Qt application involving signals and slots. A signal is emitted from a state machine running in a separate thread, initiated by a function in Class A. After the state machine completes, it emits a signal connected to a slot in Class B. In the slot execution, I'm calling the same function to run the state machine again. Could this approach potentially cause issues?

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

      @candidaj said in Emitting signal from the same slot it is connected to.:

      Can this lead to an issue?

      If you make sure you do not have an endless recursion it should be OK

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

      1 Reply Last reply
      1
      • C candidaj

        Can i emit the signal which slot is connected from the same slot again. I will make the emit from slot conditional and happen only once,to avoid recursive calling.Can this lead to an issue?

        I'm working with a Qt application involving signals and slots. A signal is emitted from a state machine running in a separate thread, initiated by a function in Class A. After the state machine completes, it emits a signal connected to a slot in Class B. In the slot execution, I'm calling the same function to run the state machine again. Could this approach potentially cause issues?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @candidaj
        As @jsulm says. But

        I will make the emit from slot conditional and happen only once,to avoid recursive calling.Can this lead to an issue?

        You might want to show the slot method with your code for this check to verify you have something safe/acceptable/reusable.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          Recursion can always lead to a place where the stack is too deeply nested. Modern compilers can convert tail recursion into a loop to avoid this problem. However, signals and slots will prevent this.

          This would only be a problem if you are using a DirectConnection for your signals and slots (which would most likely happen automatically). You should make sure that your connections (for the state machine) are QueuedConnections. Especially if the state machine is run inside the main thread a DirectConnection would block the event loop. A QueuedConnection would allow other things to be processed by the event loop as well.

          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