My application uses Qt SQL this way
QString servername = "SQL09.FreeMySQL.net";
QString dbname = "psiprobation";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
QString dsn = QString("DRIVER={MySQL ODBC 5.1 Driver};SERVER=%1;DATABASE=%2;USER=jnchappell21;PASSWORD=XXXXXXX").arg(servername).arg(dbname);
db.setDatabaseName(dsn);
I have also included this in my code…
a.addLibraryPath(a.applicationDirPath()+"/plugins");
The “plugins” folder contains another folder “sqldrivers”. Inside “sqldrivers” is myodbc5.dll, myobdc5S.dll, qsqlodbc4.dll, and qsqlodbcd4.dll. (NOTE: the “plugins” folder is in the same directory as the executable)
Now that deployment stage has come, the application works perfectly on the system where Qt is installed; however, on other systems (where QT is not installed) I am unable to connect to the database even though the application will run (i.e. the GUI opens up and displays an error message).
The error message is: “[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect”
What is the solution to this problem?
Debugging plugin issues in Qt can be a pain. I never had much success trying to force a plugin location using
addLibraryPath(). Before I ever figured out why, I discovered that Qt applications will look in the application root for the “leaf” directory of the plugin type involved. In your case, just put thesqldriversdirectory in the root of your application (without nesting it inside apluginsdirectory).One way to try to determine if you are in fact having a plugin location problem, try moving the driver files out of their location on your development machine (or rename them) and see if you get the same error.
Although directed at widget plugins, this page has some plugin trouble shooting tips.