Hi
I'm trying to better undestand how the connection to a mysal database works(http://qt-project.org/doc/qt-5.0/qts...onnecting.html).
Ther is something i'm missing about removing a connection i still miss.
#include <QSqlDatabase>
{
db->setHostName(newHostName);
db->setDatabaseName(newDatabase);
db->setUserName(newUserName);
db->setPassword(newPassword);
return db;
}
int main()
{
//QCoreApplication a(argc, argv);
bool dbStatus = false;
for(int i=0; i<2;i++)
{
if(dbStatus)
{
db->close();
db->removeDatabase("connection1");
dbStatus = false;
}
else
{
db = connection("localhost", "db01", "user1", "123");
db->open();
dbStatus = true;
}
}
}
#include <QSqlDatabase>
QSqlDatabase *connection(QString newHostName, QString newDatabase, QString newUserName, QString newPassword)
{
QSqlDatabase *db = new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL", "connection1"));
db->setHostName(newHostName);
db->setDatabaseName(newDatabase);
db->setUserName(newUserName);
db->setPassword(newPassword);
return db;
}
int main()
{
//QCoreApplication a(argc, argv);
QSqlDatabase *db;
bool dbStatus = false;
for(int i=0; i<2;i++)
{
if(dbStatus)
{
db->close();
db->removeDatabase("connection1");
dbStatus = false;
}
else
{
db = connection("localhost", "db01", "user1", "123");
db->open();
dbStatus = true;
}
}
}
To copy to clipboard, switch view to plain text mode
This code loops the connect/disconnect to database.
Why do i get the message every time i remove the database?
"QSqlDatabasePrivate::removeDatabase: connection 'connection1' is still in use, all queries will cease to work."
Bookmarks