PDA

View Full Version : QSqlDatabase: QMYSQL driver not loaded but available



alexandrius
12th July 2013, 08:37
Yeah hello there, I'm really new here.
So here's the problem.

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
I've checked many forums already and have done things so far:
1) This is my .pro file

QT += core
QT += sql
QT -= gui

TARGET = DB
CONFIG += console
CONFIG -= app_bundle

QTPLUGIN += QSQLMYSQL
TEMPLATE = app


SOURCES += main.cpp


2) This is my sqldrivers folder:

alex@alex-Laptop:~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers$ ls
libqsqlite.so libqsqlmysql.so libqsqlpsql.so

3) Have also copied sqldrivers folder to project folder.

Non of these helped an error still exists.
I have read almost everything about my problem but nothing helped.
Please help newbie with the fix.

Thanks in advance

KillGabio
12th July 2013, 08:49
post the part of the code where you open the database connection

alexandrius
12th July 2013, 09:09
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QMYSQL");

db.setHostName("teachinglessons.abcz8.com");
db.setPort(3306);
db.setDatabaseName("teachi4_test");
db.setUserName("alex");
db.setPassword("123");
qDebug()<<db.open();

KillGabio
12th July 2013, 09:24
Try giving the database a name:


db = QSqlDatabase::addDatabase("QMYSQL", "my_sql_db");


Plus, have you built the plugins?

http://harmattan-dev.nokia.com/docs/library/html/qt4/sql-driver.html#how-to-build-the-qmysql-plugin-on-unix-and-mac-os-x

alexandrius
12th July 2013, 09:26
Nothing change unfortunately

KillGabio
12th July 2013, 09:27
Read my editing, i think you are missing the step of building the plugins

alexandrius
12th July 2013, 09:35
Read my editing, i think you are missing the step of building the plugins
There's no /src/plugins/sqldrivers/mysql in my qt folder should i create it?

Sorry for stupid question

KillGabio
12th July 2013, 09:43
I have this path for example:
C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\my sqls

containing main.cpp, mysql.pro and readme.

Im running on windows, but you should have the same path i assume. Somewhere you need to have the files to generate and build your drivers.

ChrisW67
12th July 2013, 09:51
You have the Qt plugin for MySQL and it is recognised far enough to tell your program it exists. Are the MySQL run-time libraries (on which an actual database connection would depend) available on your machine?

alexandrius
12th July 2013, 10:06
KillGabio
There's nothing like that found in my Qt


ChrisW67
Yes but same problem

KillGabio
12th July 2013, 10:28
On Windows when I had the same problem i had to include the .dll of the database in this path:


C:\QtSDK\Desktop\Qt\4.8.1\mingw\plugins\sqldrivers


So that the compiler knows the libraries. For example there I have: qsqlite4.dll, qsqlocid4.dll, etc. I think you are missing the same files but for Unix (.so shared objects)

alexandrius
12th July 2013, 10:31
alex@alex-Laptop:~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers$ ls
libqsqlite.so libqsqlmysql.so libqsqlpsql.so
I have the libraries there

ChrisW67
12th July 2013, 12:11
Those are the Qt plugins, not the MySQL runtime libraries. You are looking for libmysqlclient.so somewhere on your system.

alexandrius
12th July 2013, 17:53
Those are the Qt plugins, not the MySQL runtime libraries. You are looking for libmysqlclient.so somewhere on your system.
Yeah I found them. What should I do with them?


locaalex@alex-Laptop:~$ locate libmysqlclient.so
/usr/lib/i386-linux-gnu/libmysqlclient.so.18
/usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/x86_64-linux-gnu/libmysqlclient.so
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0

KillGabio
12th July 2013, 20:25
Include them in your .pro. Example:


INCLUDEPATH += "C:/oraclexe/app/oracle/product/11.2.0/server/oci/lib/MSVC/vc10"

LIBS += -L"C:/Qt/Los taninos-killgabio/qextserialport/build" -lqextserialportd

ChrisW67
12th July 2013, 21:42
Yeah I found them. What should I do with them?
Nothing , they should be in a default library search location for the system.

What is the result when you run:


$ ldd ~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so

Are there any libraries reported missing? You might try this:


$ objdump -x /home/chrisw/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so | grep NEEDED

Does it show the same version number on the mysql related line as in your libs64 folder?

artome
30th July 2013, 18:17
I'm reviving this thread as it seems to be inactive without a answer to the problem and I was dealing with exactly the same problem for the past few days.
(with Opensuse 12.3, x86_64).

it seems that the compiled plugin that comes with the qt (qt-linux-opensource-5.1.0-x86_64-offline.bin) requires /usr/lib64/libmysqlclient_r.so.16 and opensuse comes with .18. So
doing
/usr/lib64 # ln -s libmysqlclient_r.so libmysqlclient_r.so.16

seems to solve the problem.

regards,

tselvakumars
3rd March 2014, 17:57
/usr/lib/i386-linux-gnu$ ln -s libmysqlclient_r.so libmysqlclient_r.so.16

Fixed my problem

Thanks,
Selva

martonmiklos
6th July 2014, 15:10
I have had the similar problem on Kubuntu 14.04 64 bit with the latest 5.3.1 Qt relase downloaded from the qt-project and installed to the /opt.
The Ubuntu 14.04 ships with libmysqlclient 18 while the Qt 5.3.1 is built with 16. So the creating of a symlink like above did not solved my issue.
Finally I have downloaded the libmysqlclient 16 from here:
http://packages.ubuntu.com/lucid/amd64/libmysqlclient16/download

And extraceted the library files to my /usr/lib/x86_64-linux-gnu folder.

xcxl
29th March 2016, 09:38
Had the same problem => Plugin QMYSQL & QMYSQL 3 were available but couldn't load them :
"QSqlDatabase: QMYSQL driver not loaded / QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7"

Works for me on Windows with Qt SDK 5.6.0 (32bit version with mingw 4.9.2 32bit included) :
- Downloaded MySQL 32bit in zip archive (mine was v5.7.11)
- Extracted it to C:/MySQL
- Copied "C:\Qt\QMySQL\lib\libmysql.dll" and "C:\Qt\QMySQL\lib\libmysqld.dll" to Windows/System32 (to avoid the "cannot found -llibmysql" compilation error)
- Compile with "How to Build the QMYSQL Plugin on Windows" on http://doc.qt.io/qt-5/sql-driver.html#qmysql (my command was "qmake "INCLUDEPATH+=C:\Qt\QMySQL\include" "LIBS+=C:\Qt\QMySQL\lib\libmysql.lib" sql.pro" and "mingw32-make")
- After compilation succeeded, copy (the freshly compiled) Qt5Sql.dll & Qt5Sqld.dll from "C:\Qt\Qt5.6.0\5.6\Src\qtbase\lib" to your application build directory
- Restart QtCreator, that should work