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 to signals in nested objects
Qt 6.11 is out! See what's new in the release blog

Connect to signals in nested objects

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 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.
  • Michael KM Offline
    Michael KM Offline
    Michael K
    wrote on last edited by
    #1

    Hi together,

    I do have a nested QObject structure whereas the objects (classes) are written in C++.

    It's like the following

    class InnerClass : public QObject {
        Q_OBJECT
    public:
        Q_INVOKABLE void doSomething(); // emits somethingDone()
    signals:
        void somethingDone();
    }
    
    class OuterClass : public QObject {
        Q_OBJECT
        Q_PROPERTY(InnerObject* innerObject READ getInnerObject CONSTANT)
    public:
        InnerClass *getInnerObject();
        ....
    }
    

    Then, in my QML file I instanciate an OuterClass object.

    OuterClass {
        id: outerObject
    }
    function mySomethingDone() {
        console.log("foobar called")
    }
    Component.onComplete: outerObject.innerObject.somethingDone.connect(mySomethingDone)
    

    But now, when the somethingDone signal of the InnerClass instance gets emitted I don't receive anything in my QML code. When I connect to this signal via C++ code, my slot does receive the signal.

    Does Qt have a limitation here with nested (C++) objects and QML?
    I'm using Qt 5.9.1

    Best, Michael

    1 Reply Last reply
    0
    • Michael KM Offline
      Michael KM Offline
      Michael K
      wrote on last edited by
      #2

      Okay, the problem was of other origin.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        What was that origin ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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