Originally Posted by
Lykurg
Before you remove a connection make sure all QSqlQuerry/QSqlDatabase/QSql*** object's are destroyed of cleared. Then you can remove the database.
Thanks for your answer!
I already tryed to clear close and delete all objects but the message keeps showing. I will post some of the code:
Header:
QSqlDatabase db;
To copy to clipboard, switch view to plain text mode
Constructor:
db
= QSqlDatabase::addDatabase("QMYSQL");
//select database typedb.setHostName("localhost"); //tell where the database is
db.setDatabaseName("qt"); //Database name
db.setUserName("user"); //username to connect to the database
db.setPassword("password"); //password from user
db = QSqlDatabase::addDatabase("QMYSQL"); //select database type
db.setHostName("localhost"); //tell where the database is
db.setDatabaseName("qt"); //Database name
db.setUserName("user"); //username to connect to the database
db.setPassword("password"); //password from user
To copy to clipboard, switch view to plain text mode
Function LoadProduct:
//check for errors on database connection
if (!db.open()) {
qDebug() << db.lastError();
// return 4;
}
//set table to use
//Query to get table info
query.exec("Select ProductName from "+ table);
//routine to read values
while (query.next()) {
//get ProductNames
ProductNames << query.value(record.indexOf("ProductName")).toString();
numberOfProducts++;
}
//check for errors on database connection
if (!db.open()) {
qDebug() << db.lastError();
// return 4;
}
//set table to use
QString table = "mytable";
QSqlQuery query("USE " + table);
//Query to get table info
query.exec("Select ProductName from "+ table);
//routine to read values
while (query.next()) {
QSqlRecord record = query.record();
//get ProductNames
ProductNames << query.value(record.indexOf("ProductName")).toString();
numberOfProducts++;
}
To copy to clipboard, switch view to plain text mode
How should I close it now? I already tryed, db.close(), query.clear, db.removeDatabase("QMYSQL"), delete db, delete query, QSqlDatabase::removeDatabase("QMYSQL"), etc...
Remind you that the application works most of the times but the message keeps on comming.
Bookmarks