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. Signal/Slot loop?
Qt 6.11 is out! See what's new in the release blog

Signal/Slot loop?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 458 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.
  • D Offline
    D Offline
    Dan203
    wrote on last edited by
    #1

    Let's say you have a QCombo who's value you want mirrored in a QObject variable. The QObject has a slot called setValue and a signal called valueChanged. If you linked the setValue slot to the currentTextChanged signal from the QCombo, so that the value of the QObject would be updated to match the QCombo, but then also linked the setCurrentText slot on the QCombo to the valueChanged signal, so that the QCombo always matched the value of the QObject, would that create a loop where they would just continuously keep calling the signals/slots forever? Or does the Qt framework have some sort of protection to prevent this?

    JonBJ 1 Reply Last reply
    0
    • D Dan203

      Let's say you have a QCombo who's value you want mirrored in a QObject variable. The QObject has a slot called setValue and a signal called valueChanged. If you linked the setValue slot to the currentTextChanged signal from the QCombo, so that the value of the QObject would be updated to match the QCombo, but then also linked the setCurrentText slot on the QCombo to the valueChanged signal, so that the QCombo always matched the value of the QObject, would that create a loop where they would just continuously keep calling the signals/slots forever? Or does the Qt framework have some sort of protection to prevent this?

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

      @Dan203 said in Signal/Slot loop?:

      Or does the Qt framework have some sort of protection to prevent this?

      Nope. That's your problem in your own code. This particular case is usually resolved by ensuring you only raise a valueChanged when the value is actually changing, not just being set, which stops the ping-pong signalling.

      You can assume Qt's own valueChanged and dataChanged signals are only raised when value/data is changed.

      For your particular widget-object case, note there is a QDataWidgetMapper Class. This manages the mapping between any widgets and their value in a map. You could use it for your example, or look at its code if you want to know how they do it.

      D 1 Reply Last reply
      3
      • JonBJ JonB

        @Dan203 said in Signal/Slot loop?:

        Or does the Qt framework have some sort of protection to prevent this?

        Nope. That's your problem in your own code. This particular case is usually resolved by ensuring you only raise a valueChanged when the value is actually changing, not just being set, which stops the ping-pong signalling.

        You can assume Qt's own valueChanged and dataChanged signals are only raised when value/data is changed.

        For your particular widget-object case, note there is a QDataWidgetMapper Class. This manages the mapping between any widgets and their value in a map. You could use it for your example, or look at its code if you want to know how they do it.

        D Offline
        D Offline
        Dan203
        wrote on last edited by
        #3

        @JonB said in Signal/Slot loop?:

        @Dan203 said in Signal/Slot loop?:

        Or does the Qt framework have some sort of protection to prevent this?

        Nope. That's your problem in your own code. This particular case is usually resolved by ensuring you only raise a valueChanged when the value is actually changing, not just being set, which stops the ping-pong signalling.

        You can assume Qt's own valueChanged and dataChanged signals are only raised when value/data is changed.

        That's what I figured, but wanted to make sure. Thanks

        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