Hey guys,

I currently have an issue with QtSql/QSqlDatabase libraries with Qt C++ on Debian with Qt Creator 5.8.2 (Qt 5.11.3 GCC 32 bit); my latest industrial software engineering project requires multiple MySQL database connections on different threads. After some research, it seems that I need to name my database connections. However whenever I add a second argument to QSqlDatabase::addDatabase, the drivers become unavailable.

The following code works fine and I can verify on the SQL CLI that the data is being received correctly:
Qt Code:
  1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  2.  
  3. db.setHostName("00.00.000.000");
  4. db.setDatabaseName("00000");
  5. db.setUserName("00000");
  6. db.setPassword("00000");
  7.  
  8. bool dbOk = db.open();
  9.  
  10. if(dbOk)
  11. {
  12. qDebug() << "Connected to Database.";
  13.  
  14. QString queryData;
  15. queryData.sprintf("INSERT INTO `dev`.`logs` (`logid`, `timestamp`, `command`) VALUES (NULL, CURRENT_TIMESTAMP, 'Test')");
  16.  
  17. qDebug() << "Output Query Data: " << queryData << ".";
  18.  
  19. QSqlQuery query(queryData);
  20.  
  21. if(!query.isActive())
  22. {
  23. qDebug() << "ERROR Error with database query! " << "Last Database Error: " << db.lastError() << ". Last Query Error: " << query.lastError() << ".";
  24.  
  25. }
  26. else
  27. {
  28. qDebug() << "Query is good!";
  29. }
  30. }
  31.  
  32. QString connection;
  33. connection = db.connectionName();
  34. db.close();
  35. db = QSqlDatabase();
  36. db.removeDatabase(connection);
To copy to clipboard, switch view to plain text mode 

But when I change:

Qt Code:
  1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
To copy to clipboard, switch view to plain text mode 

To:

Qt Code:
  1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "MyConnName");
To copy to clipboard, switch view to plain text mode 

I get "ERROR Error with database query! Last Database Error: QSqlError("", "", "") . Last Query Error: QSqlError("", "Driver not loaded", "Driver not loaded") .". Does anyone have any idea as to why this is happening?

Any help would be greatly appreciated!

Thanks,
Ryan