Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QList of pointers - how to prevent memory leak.
QtWS25 Last Chance

QList of pointers - how to prevent memory leak.

Scheduled Pinned Locked Moved Solved General and Desktop
qlist
3 Posts 2 Posters 437 Views
  • 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
    artwaw
    wrote on 21 Nov 2021, 14:26 last edited by
    #1

    Good morning,
    I came to the point where my knowledge is not sufficient so I'd like to ask before I implement something stupid.

    On the frontend side I have a tabwidget, where each tab has QTableView.
    For each of those table views I have QSortFilterProxyModel on top of QSqlTableModel presenting different tables from sqlite db.

    On the backend side I have single QObject based class for managing those and interacting with db.

    Now the dubious part:
    I figured that backend will store internally QList<QSortFilterProxyModel*> mModelList as to the outside world only those models should be returned (well, pointers to them).
    The creation process goes (in simplified form, without setting up the header view and such):

    QSqlTableModel *newView = new QSqlTableModel(this,db);
    newView->setTable(someTableName);
    newView->select();
    QSoftFilterProxyModel *listItem = new QSortFilterProxyModel(this);
    listItem->setSource(newView);
    mModelList.append(listItem);
    

    The question is: since all the objects have parent, are there any extra steps I need to do (like delete) on any of those or (as I assume but I might be wrong) will all the items be properly destroyed once the parent class is destroyed?
    Second question is: is my way of handling this at all sound or is there a better and more canonical approach?

    Many thanks in advance.
    Artur.

    For more information please re-read.

    Kind Regards,
    Artur

    J 1 Reply Last reply 21 Nov 2021, 16:28
    0
    • A artwaw
      21 Nov 2021, 14:26

      Good morning,
      I came to the point where my knowledge is not sufficient so I'd like to ask before I implement something stupid.

      On the frontend side I have a tabwidget, where each tab has QTableView.
      For each of those table views I have QSortFilterProxyModel on top of QSqlTableModel presenting different tables from sqlite db.

      On the backend side I have single QObject based class for managing those and interacting with db.

      Now the dubious part:
      I figured that backend will store internally QList<QSortFilterProxyModel*> mModelList as to the outside world only those models should be returned (well, pointers to them).
      The creation process goes (in simplified form, without setting up the header view and such):

      QSqlTableModel *newView = new QSqlTableModel(this,db);
      newView->setTable(someTableName);
      newView->select();
      QSoftFilterProxyModel *listItem = new QSortFilterProxyModel(this);
      listItem->setSource(newView);
      mModelList.append(listItem);
      

      The question is: since all the objects have parent, are there any extra steps I need to do (like delete) on any of those or (as I assume but I might be wrong) will all the items be properly destroyed once the parent class is destroyed?
      Second question is: is my way of handling this at all sound or is there a better and more canonical approach?

      Many thanks in advance.
      Artur.

      J Offline
      J Offline
      JonB
      wrote on 21 Nov 2021, 16:28 last edited by
      #2

      @artwaw
      Yes everything will be destroyed via parentage.
      This way of handling seems fine to me :)

      A 1 Reply Last reply 21 Nov 2021, 16:47
      2
      • J JonB
        21 Nov 2021, 16:28

        @artwaw
        Yes everything will be destroyed via parentage.
        This way of handling seems fine to me :)

        A Offline
        A Offline
        artwaw
        wrote on 21 Nov 2021, 16:47 last edited by
        #3

        @JonB Thank you!

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0

        1/3

        21 Nov 2021, 14:26

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved