Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    QML and Qt Quick
    3
    5
    1237
    Loading More Posts
    • 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
      SlimIT last edited by

      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 Reply Quote 0
      • L
        leon.anavi last edited by

        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 Reply Quote 0
        • S
          SlimIT last edited by

          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 Reply Quote 0
          • C
            chrisadams last edited by

            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 Reply Quote 0
            • S
              SlimIT last edited by

              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 Reply Quote 0
              • First post
                Last post