PDA

View Full Version : Closing Connection to Sqlite



Dydy02
12th October 2017, 03:26
i always have this kind of error. i saw that someone already asked for but my code it's different.
the connexion is right but whent i execute a query i receive this message and can't execute query again
the error:

QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Connexion reussie.

that my code. header



QSqlDatabase mydb;

bool open_data()
{
mydb = QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("C:/SQlite/SQLiteManager-1.2.4/Class1a.sqlite");

if (!mydb.open())
{
qDebug()<<("Echec de la connexion")<<mydb.lastError().text();
return false;
}
else
{
qDebug()<<("Connexion reussie");
return true;
}

}//ending function

void close_data()
{
mydb.close();
mydb.removeDatabase(QSqlDatabase::defaultConnectio n);
//

} // ending function

/////////////////

// file.cpp

void Databse:: message()

{
if (!open_data())
{
qWarning()<<"Echec de la connexion"<<mydb.lastError().text();
}


QSqlQueryModel * modal = new QSqlQueryModel;
open_data();
QSqlQuery query;
query.prepare("SELECT Name,Lastname,Balance FROM fgrade order by Name,Lastname");

if(!query.exec())
{

QMessageBox::critical(this,tr("error::"),query.lastError().text());

}
else
{
modal->setQuery(query);
tablev->setModel(modal);
close_data();
QMessageBox::warning(this,"Sauvegarde","donnees triees normalement");

}

}// ending function



i'am waiting for your assistant. please!