this is my code :

mydb.cpp
Qt Code:
  1. #include <QSqlDatabase>
  2. QSqlDatabase MyDB::connectDatabase()
  3. {
  4. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  5. // below are usernames & passwords & ports & etc...
  6. return db;
  7. }
  8.  
  9. void MyDB::removeConnection()
  10. {
  11. QSqlDatabase::removeDatabase("QMYSQL");
  12. }
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mydb.h"
  2. MyDB mydb;
  3. MainWindow::MainWindow()
  4. {
  5. {
  6. QSqlDatabase db = mydb.connectDatabase();
  7. QSqlQuery query;
  8. // perform queries here
  9. query.clear();
  10. db.close();
  11. }
  12. mydb.removeDatabase(); // not working here
  13. }
To copy to clipboard, switch view to plain text mode 

i still get this error : QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
what am i missing? i already read the docs about QSqlDatabase::removeDatabase()...
thanks...