the first:
what is this?
Qt Code:
  1. ...
  2. db->QSqlDatabase::addDatabase("QPSQL");
  3. ...
To copy to clipboard, switch view to plain text mode 
I didn't see where you create object using operator new.

the second:
you shouldn't use pointer to database, because QSqlDatabase class is shared.
so, I suggest you to revise you code: refuse using pointer to database (but if you prefer
to use pointer then you must use new operator)

you can also not to keep variable for database like a class member, you can always get a needed database object using
Qt Code:
  1. QSqlDatabase QSqlDatabase::database ( const QString & connectionName = QLatin1String( defaultConnection ), bool open = true )
To copy to clipboard, switch view to plain text mode 

conclusion:
you can use the following code
Qt Code:
  1. void someObject::initDatabse
  2. {
  3. QSqlDatabese db = QSqlDatabse::addDatabase("QPSQL", "myConnection");
  4. .....//do connection stuff
  5. }
  6.  
  7. void someObject::execQuery(const QString &queryText)
  8. {
  9. QSqlDatabse db = QSqlDatabase::database("myConnection");
  10. QSqlQuery query(db);
  11. query.prepare(queryText);
  12. ....
  13. }
To copy to clipboard, switch view to plain text mode