Good day all.

Im currently using this code in my project to open a mysql database file

..... mydatabase.cpp....

Qt Code:
  1. bool myDatabase::createDatabaseConn()
  2. {
  3. QSettings settings("ATSTech", "ats_shopfront");
  4.  
  5. settings.beginGroup("database");
  6.  
  7. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  8.  
  9. db.setHostName(settings.value("server").toString());
  10. db.setDatabaseName("dbname");
  11. db.setUserName(settings.value("databaseUsername").toString());
  12. db.setPassword(settings.value("databasePassword").toString());
  13.  
  14. if (!db.open()) {
  15. //QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
  16. return false;
  17. }
  18. return true;
  19.  
  20. settings.endGroup();
  21. }
To copy to clipboard, switch view to plain text mode 

No when i use this from my other pages like so

Qt Code:
  1. myDatabase *getinfo = new myDatabase();
  2. getinfo->createDatabaseConn();
To copy to clipboard, switch view to plain text mode 

i get the following warinings/errors

Qt Code:
  1. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
To copy to clipboard, switch view to plain text mode 

Is there any way to in the code at the top to check if there is already a connection and if so use that one instead of removing and creating a new one to the database.
im sure that would make things faster aswell

regards
Donovan Hoare