September 22, 2011

Bernhard Roth Bernhard Roth
Lab Rat
12 posts

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


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?

  1. QList<SomeObject*> SomeTool::findSomeObjects(QObject* rootObject)
  2. {
  3.     return rootObject->findChildren<SomeObject*>();
  4. }

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,

1 reply

September 22, 2011

Bernhard Roth Bernhard Roth
Lab Rat
12 posts

Stupid boy! :) Just discovered that it seems to only work to return

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

  1. 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
  1. QDeclarativeItem::setParentItem()
or did I misunderstood something conceptionally?

  ‹‹ how to use Landmark model in map element??      how to use landmark model in QML MAP ELEMENT?? ››

You must log in to post a reply. Not a member yet? Register here!