QSqlDatabase: QMYSQL driver not loaded on Mac OS - c++

I've already solved this problem on Windows and some Linux flavors, now is Mac time. It all starts with the following:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Then the solution should be more or less what is pointed in the following links i.e.:
MySQL for Qt on Mac
QSqlDatabase: QMYSQL driver not loaded on Xubuntu 16.04 64bits
QSqlDatabase: QMYSQL driver not loaded on Ubuntu 15.04 64bits
In the end a new version of (debug and release) the lib should be produced, then is a matter of replacing the old one by the new one and everything will work from now on.
I just did that and the problem is that the new lib (found in ~Qt/5.7/Src/qtbase/plugins/sqldrivers), the one just compiled with
~/Qt/5.7/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql-5.6.17-osx10.7-x86_64/include/" "LIBS += -L/usr/local/mysql-5.6.17-osx10.7-x86_64/lib/"
make
have the same size as the older (found in ~Qt/5.7/clang_64/plugins/sqldrivers). I mean, the lib just compiled is the same as the one already there. And I still get the QSqlDatabase: QMYSQL driver not loaded.
Can some one please put some light here? What's going on?
After some time I found (here) that
install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib
and
install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
helps.
I have some understanding of this but I'll leave it open to someone more knowledgeable in the field to give the details.

The critical part is to:
~/Qt/5.8/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql-5.6.17-osx10.7-x86_64/include/" "LIBS += -L/usr/local/mysql-5.6.17-osx10.7-x86_64/lib/" mysql.pro
make
And then:
cp ~/Qt/5.8/Src/qtbase/plugins/sqldrivers/ ~/Qt/5.8/clang_64/plugins/sqldrivers/

Related

libmysql.dll for 64bit Qt w/ MSVS2017 compiler

I was always working with MinGW and all I had to do to not get the infamous output was to copy a 32bit libmysql.dll file to where the executable resides:
QSqlDatabase: MYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Now I'm trying to compile my application with MSVS2017 64bit compiler. I've tried to use both the 32bit and 64bit libmysql.dll files but with no luck - I'm getting the warnings and QSqlDatabase won't open. I've found this website: https://wiki.qt.io/How_to_load_a_sql_driver_correctly but it seems to be outdated and vague. Any known solution to the problem?
With MSVS you need qsqlmysql4.dll, usually need to build your MySQL drives from sources, you can follow Qt documentation How to Build the QMYSQL Plugin on Windows to do that.

Qt Driver Postgresql available but not loaded

I'm trying to make a sample project, to read the data in my database.
I'm using Qt 5.8 on Windows 10, with mingw 32 bits compiler. Postgresql 9.6 32 bits.
I have the error :
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
I tried to add in my Path:
-PostgresPath\
-PostgresPath\include
-PostgresPath\bin
-PostgresPath\lib
I tried to copy libeay32.dll, libintl-8.dll, libpq.dll, ssleay32.dll in QTPath\5.8\mingw53_32\bin.
I tried to add libpq.dll, qsqlpsql.dll and qsqlpsqld.dll in my project folder but it doesn't help.
Do you have any advice ?
Thanks.
Maybe you do not have the exact QPSQL plugin version you actually use for development (for example due to Qt framework upgrading etc.), so the plugin exists but cannot be loaded. Try to manually build the Qt PSQL driver plugin. Download the exact version of Qt source code (5.8.0 in your case) and run following commands.
I assume that PostgreSQL was installed in C: \ psql, and the Qt source code is in% QTDIR%, build the plugin as follows:
cd %QTDIR%\src\plugins\sqldrivers\psql
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
nmake
This works for me when I had similar problem.

Qt MYSQL not working on ubuntu 15.10

I'm trying to get MYSQL working via Qt on Ubuntu 15.10, however I am having an issue when loading the plugin. I'm using the latest Qt, downloaded from their website (Qt5.6.0) but I am getting the following error when launching the application:
Got keys from plugin meta data ("QPSQL7", "QPSQL")
loaded library "/home/rob/Qt5.6.0/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so"
QLibraryPrivate::loadPlugin failed on "/home/rob/Qt5.6.0/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so" : "Cannot load library /home/rob/Qt5.6.0/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so: (libmysqlclient_r.so.16: cannot open shared object file: No such file or directory)"
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
The issue is, that libmysqlclient_r.so.16 is not even part of the ubuntu 15.10 linux distribution, which uses instead libmysqlclient_r.so.18.
I've read somewhere that clearing Qt's plugin cache may help this, but I could not find out how to do that.
What steps should I take to fix this issue?

Qt5.2 can find the mysql driver but can not load it

Operating System: win7
compiler : mingw4.8(come with Qt5.2)
link to : Fedora core release 5, kernel 2.6.15-1.2054_FC5 smp on an i686
db = new QSqlDatabase();
db->addDatabase("QMYSQL");
db->setHostName("localhost");
db->setDatabaseName("myclinic");
db->setUserName("root");
db->setPassword(",trth12");
qDebug() << loader.errorString();
qDebug() << "drivers: "<< QSqlDatabase::drivers();
if (db->open())
qDebug() << "Success!";
else
qDebug() << db->lastError().text();
messages
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available
drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL 7 “The shared
library was not found.” drivers: (“QSQLITE”, “QMYSQL”, “QMYSQL3”,
“QODBC”, “QODBC3”, “QPSQL”, “QPSQL7”)
“Driver not loaded Driver not loaded”
You seem to be either missing the mysql plugin on your Windows or the proper mysql installation itself in which case you will need to get that done by installing all the necessary mysql libraries on your system where the plugin QtSql driver can recognize it.
The plugin should be available under the plugins/sqldrivers folder as a dll. You could also put it into an sqldrivers folder beside your application, so somethiing like this:
- yourapplication.exe
- sqldrivers/qsqlmysql4.dll
You would need to grab it somehow, or build it yourself. This is the explanation from the documentation how to do so:
How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):
cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
nmake
If you are not using a Microsoft compiler, replace nmake with make in the line above.
There is another problem with your code though. You should be using "127.0.0.1" instead of "localhost" for mysql databases.
Thanks for the answer, but the problem is not because I lack the qsqlmysql.dll but I don't have the libmysql.dll(looks like this dll do not come with win7).
Here is a video which show you how to install mysql
I had the same Pb of you
Solution is:
The Qt MySQL drivers is already inside Qt5 (but not in the previous version!)
You just need the "libmysql.dll" next to your app exe (or in windows directory!) You find "libmysql.dll" in "mysql\mysqlX.X.XX\lib\opt" directory.
If Qt MySQL driver not found the libmysql.dll the error is the same as the driver is not found...
Good chance for the next!

Qt QPSQL driver problem

I'm trying to connect postgresql with Qt SQL module. I successfully compile psql driver(src\plugins\sqldrivers\psql). But when i try to connect postgresql, i get this message;
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL QODBC3 QODBC QPSQL7 QPSQL
I'm using PostgreSQL 8.3, Qt 4.7.1 and Visual Studio 2008 in Windows XP SP3.(I also try this, but didn't help)
Did you compile the release and debug versions of the plugin? The output of the dependency walker looks like you work with the debug version. You should have qsqlpsql4.dll and qsqlpsqld4.dll in the %QTDIR%\plugins\sqldrivers directory. You can check the plugin path that is used in your program with: QString QLibraryInfo::location ( QLibraryInfo::PluginsPath );