In most cases a warning "QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed" occurred while adding or closing database in Qt.
How to solve this problem?
// WRONG
How to solve this problem?
// WRONG
QSqlDatabase db = QSqlDatabase::database("mydb");//Closing database connection in CORRECT way
QSqlQuery query("SELECT ...", db);
QSqlDatabase::removeDatabase("mydb"); // will output the above warning
db.close();And also you can check the database connection is empty or not.
db = QSqlDatabase();
QSqlDatabase::removeDatabase("mydb");
if(db.connectionName().isEmpty())
{
//Add database.
}
No comments:
Post a Comment