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. I need to connect a ComponentA Signal to a method of another ComponentB
QtWS25 Last Chance

I need to connect a ComponentA Signal to a method of another ComponentB

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.5k 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.
  • S Offline
    S Offline
    SlimIT
    wrote on last edited by
    #1

    Hi,

    i need to create a ComponentC dynamically when a button of ComponentA is clicked and the ComponentC must be created in ComponentB that is not accessible through id from ComponentA.

    So how is this realisable ?

    Thanks.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      You should be able to achieve this using "signals and slots":http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html. You can connect a signal emitted by your ComponentA to a method of your ComponentB using the "QObject::connect":http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#connect. Check the "documentation":http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html for details.

      http://anavi.org/

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SlimIT
        wrote on last edited by
        #3

        I think that i can't do that with the Qt Core because i'm using QtQuick QML.

        I was able to do that with the "Connections":https://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-connections.html Component.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          You can also use the dynamic signal connection syntax.

          @
          Component.onCompleted: {
          someObjectId.someSignal.connect(otherObjectId.methodName)
          }
          @

          A connections element is less error-prone, and more declarative - but does involve the instantiation of a QObject, and has some performance implications. In most cases, I'd suggest the use of the Connections element, but there are times when using an imperative signal connection is the better choice.

          Cheers,
          Chris.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SlimIT
            wrote on last edited by
            #5

            Thank you but i have a new problem with connections.

            Why i can't sometime access someObject with his unique ID ?

            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