QList of pointers - how to prevent memory leak.
-
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 internallyQList<QSortFilterProxyModel*> mModelListas 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. -
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 internallyQList<QSortFilterProxyModel*> mModelListas 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. -
@artwaw
Yes everything will be destroyed via parentage.
This way of handling seems fine to me :)