I am creating an application in qt which uses sqlite database. I have written a class to open database connection. The constructor for the class is given below:
currencydb::currencydb()
{
currency = QSqlDatabase::addDatabase("QSQLITE");
currency.setDatabaseName("currency.sqlite");
if(!currency.isOpen())
{
if (!currency.open())
{
qDebug() << "Error: connection with database fail";
}
else
{
qDebug() << "Database currency: connection ok";
}
}
}
Since i use this constructor, when i create object for the database class, i get following warning:
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Is there a way to check in the constructor whether the database is already open?
Aucun commentaire:
Enregistrer un commentaire