Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QT example sqlbrowser : clarification about variables scopes
Hi all, I am reading the QT example sql_browser and one question pops up in my mind. This is also related to basic C++ I guess (scopes).
void Browser::exec()function (browser.cpp, line 84), the model to the table view is changed to display the output of the query typed in the sqlEdit part. In this function, a new pointer is created to a QSqlQueryModel. Later in the execution, the model of the TableView can be changed.
My question is what happen to the model pointer created in the
execfunction once the model associated to the table view is changed. As far as I understand, there is no reference anymore to that pointer, so it seems to be memory leak. Am I right?
Then suppose the user is entering in the same function again. I would say then that a new pointer will be created for another QSqlQueryModel. Is it right or does it uses the same memory space as the previous execution of this function?
Thank you for your help
There is no leak since a parent is passed to QSqlQueryModel even though you're correct - a 'delete view->model()' before setting the new one would be better here.
Ok thank you for the clarification :)
Then please mark this topic as solved, thx.
@Christian-Ehrlicher I put it as a general discussion thread as it it not really a problem. Is that ok?
@Thombou Yes :)