Hello
Can someone assist me a bit please.
I have set up a class to do the connecting to a database as follows:

Qt Code:
  1. void DBMySQL::setupConnectionToDB()
  2. {
  3. db = QSqlDatabase::addDatabase("QMYSQL", m_ConnectionName);
  4. db.setDatabaseName(m_Database);
  5. db.setHostName(m_Host);
  6. db.setUserName(m_User);
  7. db.setPassword(m_Password);
  8. db.setConnectOptions();
  9. db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
  10. ...
To copy to clipboard, switch view to plain text mode 

I am wanting to set up multiple connections, and hence the m_ConnectionName.

I also have a function to query the database:
Qt Code:
  1. QStringList DBMySQL::getData(QString queryString)
  2. {
  3. QSqlQuery query;
  4. m_DBState = query.exec(queryString);
  5. if (m_DBState) {
  6. query.setForwardOnly(true);
  7. int fieldCount = query.record().count();
  8. m_Result = QString::number(fieldCount,10) + " batches retrieved";
  9. while (query.next()) {
  10. QString str("");
  11. for (int i = 1; i <= fieldCount ; ++i) {
  12. if (i == fieldCount)
  13. str = str + query.value(i-1).toString();
  14. else
  15. str = str + query.value(i-1).toString() + ",";
  16. }
  17. sl << str;
  18. }
  19. }
  20. else
  21. m_Result = "Could not retrieve data";
  22. m_ErrorMsg = db.lastError().text();
  23. emit dbState(m_DBState, m_Result, m_ErrorMsg);
  24. return sl;
  25. }
To copy to clipboard, switch view to plain text mode 

This returns the result of the query in a QStringList.

Now from my calling function I have done the following:

Qt Code:
  1. dbConnector1 = new DBMySQL("server1","database1","user1","pw1","default");
  2. dbConnector2 = new DBMySQL("server1","database2","user2","pw2","other");
To copy to clipboard, switch view to plain text mode 

where dbConnector 1 & 2 are of type DBMySQL

I have a MainWindow with a combobox on, and I want to populate it:

Qt Code:
  1. void MainWindow::extractBatches(QString modelName)
  2. {
  3. QString queryString = "SELECT DISTINCT batch_no FROM doicii_5_6k ORDER BY batch_no";
  4. QStringList batchList = dbConnector2->getData(queryString); //from "other" database
  5. ui->comboBoxBatch->insertItems(0,batchList);
  6. ui->comboBoxBatch->setCurrentIndex(-1);
  7. }
To copy to clipboard, switch view to plain text mode 

However, I get the following error:

QSqlQuery::exec: database not open
QSqlDatabasePrivate::removeDatabase: connection 'default' is still in use, all queries will cease to work.
QSqlDatabasePrivate::removeDatabase: connection 'other' is still in use, all queries will cease to work.
Can someone explain what I am doing wrong?

My reason for wanting to access different databases is because there are already existing databases in use, I want info from more than one in my program, sort of like making a report based on all data from all databases. I will then take this data and put it into the "default" database.

Regards,
Shaun