Why does exposing a QList<MyObject*> from C++ to QML through notifiiable method crash the application? (Big Topic: finding child objects of specific t

  • Hello,
    I'm new to this forum but I hope that I'm somehow able to express my concerns. :)

    Essentially, what I want to do is, to create/gather a list of all objects of a specific type (eg. MyRectangle) used throughout an object tree and assign it as a model to some view (e.g. to change/show their properties). Since I don't see any possibility to do this directly in QML, I decided to do this through an invokable C++ method that looks as simple as the following function but whenever I call this function from QML the application segfaults. Interestingly this seems to happen after the method returns (I tested this by logging) and it did work in 4.7.1 and now it doesn't? Is it a bug or is this not expected to work?

    @QList<SomeObject*> SomeTool::findSomeObjects(QObject* rootObject)
    return rootObject->findChildren<SomeObject*>();

    Are there any alternatives to this idea, especially since I already realized that findChildren seems to somehow ignore object trees below the rootObject that are created through C++ which is also a bit awkward..

    Thanks in advance,

  • Stupid boy! :) Just discovered that it seems to only work to return @QList<QObject*>@ and not QObject derived types. 4.7.1 let me do nothing with it and because of 4.7.4 crashing I read one or two (hundred ;) ) times again through the docs... But now it works flawlessly! :)

    PS: The problem that @QObject::findChildren<SomeObject*>()@ does not find all children in the subtree remains, any ideas? Shouldn't they be there if I set their parent through @QDeclarativeItem::setParentItem()@ or did I misunderstood something conceptionally?

Log in to reply