Basically when I try to connect to the mysql database i get this error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3
I tried to install the drivers, extracting just qtbase from http://download.qt-project.org/official_releases/qt/5.0/5.0.2/single/qt-everywhere-opensource-src-5.0.2.zip and placing it in my Qt directory. I have also followed this guide by inbush: http://www.qtcentre.org/threads/45295-using-mysql-plugin doing this: http://puu.sh/3nyG9.png
inbush says to copy libmysql.dll from C:\mysql\bin to C:\Qt\bin but I didn't find libmysql.dll in bin, but I did find it in lib. So I took that and went to my Qt\bin, and noticed that it was just these files http://puu.sh/3nB5m.png so I thought to place it in Qt\lib instead. I tried re-running my project but it still gave me the same error. My .pro file does indeed have Qt += sql, and I did run qmake afterwards. What am I doing wrong?
Take a look at this post for Qt5, there's also a seperate set of instructions for Qt4 (although somewhat similar).
Qt - How to get|compile Mysql driver
Download a version of MySQL
Download Qt source
Build the MySQL plugin for Qt
Copy the DLL from the MySQL install folder to a Qt folder (see link above)
Copy the DLL you built for the Qt MySQL plugin to a Qt folder
And obviously, when you distribute you'll need to remember to package those DLLs together (always check dependency walker)
Related
I started to notice that after version 5.12.3 none more came with the plugin driver, I can't find any information about removing the plugin, I also tried to compile it through this tutorial: https://www.youtube.com/watch?v=r1TbNjJSlX8, but to my surprise I didn't have the source for the sql module in the source files
I'm trying to use a MySQL database in a QT application. For this I needed to build the MySQL manually and nothing went as planned at all.
Using:
Qt 5.12.5
g++ 8.3.0
Make 4.2.1
MySQL 15.1
Debian 10.1
I first tried to follow this guide: https://doc.qt.io/qt-5/sql-driver.html but qmake wouldn't detect MySQL headers.
After searching the internet I found out somebody managed to work things out by building directly the driver.
I went in ~/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/mysql and ran :
qmake qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/x86_64-linux-gnu/ -lmysqlclient_r"
It didn't work :
Project ERROR: Library 'mysql' is not defined.
After some googling, I changed the mysql.pro file to this one:
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)
It worked, for now. Next step, running make ! Guess what? Didn't work either.
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
ran qmake again without "INCLUDEPATH [...]", now I was missing mysql.h. I added manually the path to it to the Makefile. It worked.
I tried running my QT app again, still no MySQL driver.
Turned out the newly built driver was not copied in the right directory with the other ones. So I copied in Qt/5.12.5/gcc_64/plugins/sqldrivers.
Now it seems my plugin is indeed recognized by Qt but it just crashes with this error :
Cannot mix incompatible Qt library (version 0x50b03) with this library (version 0x50c05)
I don't know what to do next, can't find anything useful for this case on the internet...
Help, please?
Turned out I had another version Qt installed on my system. I don't where it came from but this issue is now solved.
I have a problem with Qt connecting with MySql, when i run this code
QSqlDatabase DBObject = QSqlDatabase::addDatabase("QMYSQL");
DBObject.setHostName("localhost");
DBObject.setDatabaseName("SingleDB");
DBObject.setUserName("root");
DBObject.setPassword("abc123");
bool ok = DBObject.open();
and I got this... QSqlDatabase: QMYSQL driver not loaded
I Have already done this also:
sudo apt-get install libmysqlclient
and
/home/wrm/Qt/5.12.3/gcc_64/bin/qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
and here i have this error: Project ERROR: Library 'mysql' is not defined
Any idea?
Perhaps you need to install mysql-devel.
According to the Qt Docs QMYSQL for MySQL 4 and higher:
How to Build the QMYSQL Plugin on Unix and macOS
You need the MySQL header files, as well as the shared library libmysqlclient.so. Depending on your Linux distribution, you may need to install a package which is usually called "mysql-devel".
Google doesn't have a readily available answer, so answering this old question:
Aside from needing development files as pointed above (like apt install libmysqlclient-dev), you need to generate a config:
# Just for making my snippet work. Feel free to hardcode paths.
export QTDIR=/home/you/Qt/
export QTVERSION=5.9.5
cd $QTDIR/$QTVERSION/Src/qtbase/src/plugins/sqldrivers
$QTDIR/$QTVERSION/gcc_64/bin/qmake sqldrivers.pro
cd mysql
make
make install # if you want; it installs it in the bin dir of $QTVERSION
In the past, this was not necessary for Qt 5.5 (where I did this last time).
On a side note, there is no longer a special thread-safe version of libmysqlclient (libmysqlclient_r). It's just one one. Last time I ran into that link error, I just edited the generate Makefile to use the non-_r.
Trying to connect to MySQL using
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
gives me the
Driver not loaded error
Reading the other questions and answers did not help me because they have qt4 instead of 5 that I am using, and they had to build the drivers themselves. I do have the drivers though
And I also did load the path in the pro file here
So why is this happening? Should I try and compile the drivers myself as suggested in some other questions?
EDIT
I also did make sure to use MySQL 32bit.
In Debug Mode on development machine the Qt-Framework Installation is enough.
In Release Mode you will have to provide the required driver in the sqldrivers-folder located in your working directory: $(wcd)/sqldrivers/*
Edit:
Check output of: QSqlDatabase::drivers () Eventually rebuild sql drivers for your system using $QTDIR/src/plugins/sqldrivers/mysql/mysql.pro.
Also try adding mysql-client-library to your working directory directly or setting up a library path to look for. It is not enough to add INCLUDEPATH / LIB in pro file, since this is for compile/link time only. During runtime the executable looks in the known places (typical windows: $WINDIR/system32/;$PATH;...)
After installing from the RPM and then trying the Binary versions of APE (AJAX Push Engine) I am getting this error (on both versions) when I try to run the APE server:
[Module] Failed to load ../modules/libmod_spidermonkey.so [Invalid library] (libmysqlclient_r.so.15: cannot open shared object file: No such file or directory)
I am using Fedora Linux, with MySql and apache installed. How can I get this libmysqlclient file? I have found this RPM: http://rpm.pbone.net/index.php3/stat/4/idpl/12471829/dir/fedora_4/com/mysqlclient15-5.0.67-1.fc4.remi.i386.rpm.html
And it says it includes this file, so I downloaded it to the box, attempted to install and tells me that it's already installed.
Any advice would help thanks!
Inside the ape.conf there's a module working directory which must be altered.