The following code creates an invalid (empty) QSqlDatabase object:
QSqlDatabase* db = new QSqlDatabase();
To copy to clipboard, switch view to plain text mode
To get a valid one you have to call QSqlDatabase::addDatabase.
Your second example calls this method in a wrong way. You ignore the returned object. So your QSqlDatabase object still be invalid.
In your first example it's right.
Btw: Do you want to use this code?
if (!db.open()) {
return true;
}
if (!db.open()) {
return true;
}
To copy to clipboard, switch view to plain text mode
It seems not logical?! (IMHO return false; would be better
)
Bye
Bookmarks