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.
Forum Updated to NodeBB v4.3 + New Features

QList of pointers - how to prevent memory leak.

Scheduled Pinned Locked Moved Solved General and Desktop
qlist
3 Posts 2 Posters 554 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on 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

    JonBJ 1 Reply Last reply
    0
    • artwawA artwaw

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      artwawA 1 Reply Last reply
      2
      • JonBJ JonB

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

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @JonB Thank you!

        For more information please re-read.

        Kind Regards,
        Artur

        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