Reputation: 3032
I built qt with -plugin-sql-mysql -plugin-sql-sqlite flags. I have libqsqlmysql.a and libqsqlite.a. I use qt in my project. But my build system is not qt, I use waf.
I have the following problem when I try to run my application which establishes connection with mysql database:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers:
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
INFO - Failed to connect to root mysql admin
I added -lqsqlmysql to compiler options when I build the app.
Can you please explain how qt drivers work, how and when it tries to load driver. What is a qt driver (dll, lib, ....)?
Upvotes: 2
Views: 7404
Reputation:
I think your app is trying to load the database plugin dynamically, from a DLL. This document will help you find the appropriate location for the database driver DLL. Alternatively, you could link your app against the plugin statically, here's how.
Upvotes: 3
Reputation: 111
Qt has plugins for several types of databases and these plugins are located in the following location:
$(QTDIR)/plugins/sqldrivers
First check if mysql plugin is present there. If plugin is not there then it means you didn't compile Qt properly, so you should recompile Qt with enabled MySql plugin. Otherwise probably your application doesn't load mysql plugin properly. Qt plugins are loaded dynamically during initialization of application i.e when QSqlDatabase object will be initialized. If plugin location is not set properly then none of plugins will be loaded. You can check location where your application expect to find plugins via following Qt API:
QStringList QCoreApplication::libraryPaths ()
If application doesn't point to right location you can set plugin path by calling of:
void QCoreApplication::addLibraryPath ( const QString & path )
Or by creation of qt.conf file in folder where your executable is placed. In this file you can configure plugins location in the following way:
[Paths]
Plugins = %pluginlocation%
Upvotes: 2