Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
do i have to delete query object pointer?
-
when i create a
QSqlQuery
in the heap with database, do i need to delete the object later, or the database takes care of that?
m_pQuery = new QSqlQuery(QSqlDatabase::database());
-
Hi,
Yes, you have to.
However, if you re-read the API making use of QSqlQuery, you'll see none of them uses objects allocated in the heap.
-
@sgaist
okay, in that case i guess i'll store just a member object.
-
Why do you need to store that query as member variable ?
-
@sgaist
well i'm creating and executing the query in a data source class (for table view), then each colomn takes the query from the data source and gets appropriate value from it.
-
Then you should rather keep the string of the query and build the QSqlQuery object when you actually need it.
-
@sgaist
then how will the columns get the results?
-
Can you share the code you are using ?
It looks like you could make use of a QSqlQueryModel.
-
@sgaist
no i'm on mobile now, and soon to sleep. will take a look at it tomorrow and see if i can use it. thanks
-
@SGaist
i took a look atQSqlQueryModel
but i guess i can't use it because my table view already has a model.
-
What kind ?
-
@sgaist
it isQAbstractTableModel
-
You can replace your model unless you are doing something special with it ?
-
@sgaist
that's the thing. i can't replace it cause it's doing a lot of things (it's part of a library someone has created and I'm using it)
-
How are you using it since you need to query a database ?
-
@sgaist
it has some long logic built into it, it sets up a lot of connections etc.