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

Signal/Slot system inside QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.6k 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
    DavidM29
    wrote on last edited by DavidM29
    #1

    Hello,
    I would like to use a signal/slot system on the QML side.

    I don't know how to achieve this.
    Here is an example of architecure that I want it to work with :
    0_1535622639780_51a9bd39-9cfb-48f8-aab5-eab764e56a7f-image.png

    I want the sub1 and sub 2 to emit a signal.
    This signal should trigger an action on the component2

    I found this on this subject : http://doc.qt.io/archives/qt-4.8/qmlevents.html
    But I don't see how to connect the signal from sub2 to component2.
    What is the best way to do that ?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rweickelt
      wrote on last edited by
      #2

      Do you really want to load separate QML documents and connect the objects in those? This is not the intention behind QML. Usually, you have one main file that instantiates the whole object tree like this:

      // Main.qml
      Main {
          // defined in Component1.qml
          Component1 {
              Sub1 {
                  // ...
              }
          }
      
          Component2 {
              // ....
          }
      }
      

      Usually, you would just attach signal handlers to signals as shown here instead of creating explicit connections. Slots behave like Javascript functions in QML, so you would write a signal handler like this:

      SomeComponent {
          onSomeSignal { destination.someSlot(); }
      }
      

      But you can also create connections explicitly using the built-in Connections type.

      Does that answer your question?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3

        @rweickelt
        I'm not sure to really understand.

        My code at the moment is made like you describe in your message :

        // Main.qml
        Main {
            // defined in Component1.qml
            Component1 {
                Sub1 {
                    // ...
                }
            }
        
            Component2 {
                // ....
            }
        }
        

        What I'm doing is that I make some kind of simulator for a display and a controller.
        Let's say my controller is Component 1 and the display is Component 2.
        In my controller is made of 2 kind of button (Sub1 and sub2) those buttons have to emit signal on press but the action has to be done in the display side.
        Here is what I'm exactly trying to do. Maybe I'm not thinking it right, if so please can you guide me to the good solution ?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rweickelt
          wrote on last edited by
          #4

          Please read the documentation that I have linked in my reply. It contains a lot of code examples how to work with signals and slots in QML.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DavidM29
            wrote on last edited by
            #5

            @rweickelt
            I did (even before you reply, I put this link in my first post) but it shows example only inside the same component. My issue here is that I have multiple component that need to communicate.

            The only way I see for the moment is to create multiple alias in every single qml file. But I'm pretty sure there is another way to do this.

            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