Connect to signals in nested objects



  • 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



  • Okay, the problem was of other origin.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What was that origin ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.