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.
Qt Code:
  1. #include <QSqlDatabase>
  2.  
  3. QSqlDatabase *connection(QString newHostName, QString newDatabase, QString newUserName, QString newPassword)
  4. {
  5. QSqlDatabase *db = new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL", "connection1"));
  6. db->setHostName(newHostName);
  7. db->setDatabaseName(newDatabase);
  8. db->setUserName(newUserName);
  9. db->setPassword(newPassword);
  10. return db;
  11. }
  12.  
  13. int main()
  14. {
  15. //QCoreApplication a(argc, argv);
  16. bool dbStatus = false;
  17. for(int i=0; i<2;i++)
  18. {
  19. if(dbStatus)
  20. {
  21. db->close();
  22. db->removeDatabase("connection1");
  23. dbStatus = false;
  24. }
  25. else
  26. {
  27. db = connection("localhost", "db01", "user1", "123");
  28. db->open();
  29. dbStatus = true;
  30. }
  31. }
  32. }
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."