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. Why does exposing a QList<MyObject*> from C++ to QML through notifiiable method crash the application? (Big Topic: finding child objects of specific t
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 2.3k 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.
  • B Offline
    B Offline
    b.roth
    wrote on last edited by
    #1

    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,
    Bernhard

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b.roth
      wrote on last edited by
      #2

      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?

      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