Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Connect signal to slot programmatically in QML ?
Forum Update on Monday, May 27th 2025

Connect signal to slot programmatically in QML ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 788 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • jeremy_kJ jeremy_k

      Without evaluating the validity of the approach, Connections might do what OP is asking for.

      Connections {
          target: root.dataRef
          function onValueChanged(key, value) { ... }
      }
      

      Edit: This seems to have already been discussed in https://forum.qt.io/post/740870

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #7

      https://doc.qt.io/qt-6/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals

      Signal objects have a connect() method to a connect a signal either to a method or another signal. When a signal is connected to a method, the method is automatically invoked whenever the signal is emitted. This mechanism enables a signal to be received by a method instead of a signal handler.

      Eg:

      Item {
          id: item
          onComponentCompleted: item.xChanged.connect(function(x) { console.log("x = " + x); })
      } 
      

      Asking a question about code? http://eel.is/iso-c++/testcase/

      SPlattenS 1 Reply Last reply
      1
      • oria66O Offline
        oria66O Offline
        oria66
        wrote on last edited by
        #2

        You should take a look at connect() function.

        See this, https://stackoverflow.com/questions/53482999/qml-connect-signal-to-function

        The truth is out there

        SPlattenS 1 Reply Last reply
        0
        • oria66O oria66

          You should take a look at connect() function.

          See this, https://stackoverflow.com/questions/53482999/qml-connect-signal-to-function

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #4

            you can but not not sure it will work with QQmlPropertyMap, since it is a bit of a magic type.

            SPlattenS 1 Reply Last reply
            0
            • GrecKoG GrecKo

              you can but not not sure it will work with QQmlPropertyMap, since it is a bit of a magic type.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by jeremy_k
                #6

                Without evaluating the validity of the approach, Connections might do what OP is asking for.

                Connections {
                    target: root.dataRef
                    function onValueChanged(key, value) { ... }
                }
                

                Edit: This seems to have already been discussed in https://forum.qt.io/post/740870

                Asking a question about code? http://eel.is/iso-c++/testcase/

                jeremy_kJ 1 Reply Last reply
                0
                • jeremy_kJ jeremy_k

                  Without evaluating the validity of the approach, Connections might do what OP is asking for.

                  Connections {
                      target: root.dataRef
                      function onValueChanged(key, value) { ... }
                  }
                  

                  Edit: This seems to have already been discussed in https://forum.qt.io/post/740870

                  jeremy_kJ Offline
                  jeremy_kJ Offline
                  jeremy_k
                  wrote on last edited by
                  #7

                  https://doc.qt.io/qt-6/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals

                  Signal objects have a connect() method to a connect a signal either to a method or another signal. When a signal is connected to a method, the method is automatically invoked whenever the signal is emitted. This mechanism enables a signal to be received by a method instead of a signal handler.

                  Eg:

                  Item {
                      id: item
                      onComponentCompleted: item.xChanged.connect(function(x) { console.log("x = " + x); })
                  } 
                  

                  Asking a question about code? http://eel.is/iso-c++/testcase/

                  SPlattenS 1 Reply Last reply
                  1
                  • jeremy_kJ jeremy_k

                    https://doc.qt.io/qt-6/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals

                    Signal objects have a connect() method to a connect a signal either to a method or another signal. When a signal is connected to a method, the method is automatically invoked whenever the signal is emitted. This mechanism enables a signal to be received by a method instead of a signal handler.

                    Eg:

                    Item {
                        id: item
                        onComponentCompleted: item.xChanged.connect(function(x) { console.log("x = " + x); })
                    } 
                    
                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #8
                    This post is deleted!
                    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