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. Releasing in QObjectList-based model
Forum Updated to NodeBB v4.3 + New Features

Releasing in QObjectList-based model

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.2k 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.
  • A Offline
    A Offline
    andrewnm
    wrote on last edited by
    #1

    Hello,

    In document "Using C++ Models with Qt Quick Views" I've found description of an QObjectList-based model, which mostly looks cool for easy usage when you need to provide some data into QML, except one thing that I cannot really understand: how such a list is supposed to be released? There is a reference to the example, where QObject's are created without any parent explicitly specified:

    @
    QList<QObject*> dataList;
    dataList.append(new DataObject("Item 1", "red"));
    dataList.append(new DataObject("Item 2", "green"));
    dataList.append(new DataObject("Item 3", "blue"));
    dataList.append(new DataObject("Item 4", "yellow"));
    @

    And also there is no any explicit destruction of the objects in this list. I've checked the whole example and put debug messages into DataObject destructor - it does not called at all.

    So my question is: Is Qt Quick engine responsible for such a model releasing (by deleting of each object in a list), or it is developer responsibility to make sure that everything is properly released? Can it be that example code contains mistake that is widely reproduced by other developers in their projects?

    Thanks for answers.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Unless you assign a parent, you are responsible for deleting the object.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andrewnm
        wrote on last edited by
        #3

        Yeah, but sometimes, Qt library uses re-parenting, like here:

        @QNetworkAccessManager::setCookieJar(QNetworkCookieJar * cookieJar)@

        bq. Note: QNetworkAccessManager takes ownership of the cookieJar object.

        Well.. in case of QObjectList-based model there is no any notes like that, but in example there is no any parenting for item objects.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          If the objects are needed for the whole duration of the execution, then no parent is strictly needed: the memory will be cleaned by the operating system after you close the application.

          It would be much better to provide an example that does set a parent, you are right. You can file a bug report.

          (Z(:^

          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