Cant build QMYSQL driver on Ubuntu 22.04.2 LTS
-
I want to connect mysql database with Qt GUI. I dont have QMYSQL drivers installed so I started following the documentation here but can't seem to build it.
My ubuntu is
Ubuntu 22.04.2 LTS
I installed Qt creator using
sudo apt install qtcreator qtbase5-dev
I installed MySql using
sudo apt install mysql-server
I did could not find the required libmysqlclient.so file on my system so I used the following to get it:
sudo apt install libmysqlclient-dev
After that I followed the documentation as mentioned above. I had to run (qmake -- MYSQL_PREFIX=/usr/local) in the folder ($QTDIR/qtbase/src/plugins/sqldrivers) as stated in the documentation. I am running the command in (/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers) directory. When I run the command the output is:
$ qmake -- MYSQL_PREFIX=/usr/local Usage: /usr/lib/qt5/bin/qmake [mode] [options] [files] QMake has two modes, one mode for generating project files based on some heuristics, and the other for generating makefiles. Normally you shouldn't need to specify a mode, as makefile generation is the default mode for qmake, but you may use this to test qmake on an existing project Mode: -project Put qmake into project file generation mode In this mode qmake interprets [files] as files to be added to the .pro file. By default, all files with known source extensions are added. Note: The created .pro file probably will need to be edited. For example add the QT variable to specify what modules are required. -makefile Put qmake into makefile generation mode (default) In this mode qmake interprets files as project files to be processed, if skipped qmake will try to find a project file in your current working directory Warnings Options: -Wnone Turn off all warnings; specific ones may be re-enabled by later -W options -Wall Turn on all warnings -Wparser Turn on parser warnings -Wlogic Turn on logic warnings (on by default) -Wdeprecated Turn on deprecation warnings (on by default) Options: * You can place any variable assignment in options and it will be * * processed as if it was in [files]. These assignments will be * * processed before [files] by default. * -o file Write output to file -d Increase debug level -t templ Overrides TEMPLATE as templ -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value -help This help -v Version information -early All subsequent variable assignments will be parsed right before default_pre.prf -before All subsequent variable assignments will be parsed right before [files] (the default) -after All subsequent variable assignments will be parsed after [files] -late All subsequent variable assignments will be parsed right after default_post.prf -norecursive Don't do a recursive search -recursive Do a recursive search -set <prop> <value> Set persistent property -unset <prop> Unset persistent property -query <prop> Query persistent property. Show all if <prop> is empty. -qtconf file Use file instead of looking for qt.conf -cache file Use file as cache [makefile mode only] -spec spec Use spec as QMAKESPEC [makefile mode only] -nocache Don't use a cache file [makefile mode only] -nodepend Don't generate dependencies [makefile mode only] -nomoc Don't generate moc targets [makefile mode only] -nopwd Don't look for files in pwd [project mode only]
I have tried running qmake -- MYSQL_PREFIX=/usr/include/mysql aswell but I get the same result.
I dont have any directory such as $QTDIR/qtbase/src/plugins/sqldrivers ...What should I do to build and install the driver for QMYSQL on ubuntu?
-
@SaadAli
Runningqmake
is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything viaapt
all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.I cannot remember precisely what you have fetch from
apt
to get all the necessary components (don't forget you can type e.g.apt install libmysql
and hit the Tab key twice to see available components). Do not proceed to anyqmake
steps. After yoursudo apt install libmysqlclient-dev
where are you in terms of runnability for a minimal program attempting to useQSql...
stuff?@JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:
I cannot remember precisely what you have fetch from apt to get all the necessary components
Try
apt install libqt
-Tab-Tab. I think you needlibqt5sql5-mysql
?Is there also a need for a
libqsqlmysql.so
? (Maybe that comes in the above package?) -
I want to connect mysql database with Qt GUI. I dont have QMYSQL drivers installed so I started following the documentation here but can't seem to build it.
My ubuntu is
Ubuntu 22.04.2 LTS
I installed Qt creator using
sudo apt install qtcreator qtbase5-dev
I installed MySql using
sudo apt install mysql-server
I did could not find the required libmysqlclient.so file on my system so I used the following to get it:
sudo apt install libmysqlclient-dev
After that I followed the documentation as mentioned above. I had to run (qmake -- MYSQL_PREFIX=/usr/local) in the folder ($QTDIR/qtbase/src/plugins/sqldrivers) as stated in the documentation. I am running the command in (/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers) directory. When I run the command the output is:
$ qmake -- MYSQL_PREFIX=/usr/local Usage: /usr/lib/qt5/bin/qmake [mode] [options] [files] QMake has two modes, one mode for generating project files based on some heuristics, and the other for generating makefiles. Normally you shouldn't need to specify a mode, as makefile generation is the default mode for qmake, but you may use this to test qmake on an existing project Mode: -project Put qmake into project file generation mode In this mode qmake interprets [files] as files to be added to the .pro file. By default, all files with known source extensions are added. Note: The created .pro file probably will need to be edited. For example add the QT variable to specify what modules are required. -makefile Put qmake into makefile generation mode (default) In this mode qmake interprets files as project files to be processed, if skipped qmake will try to find a project file in your current working directory Warnings Options: -Wnone Turn off all warnings; specific ones may be re-enabled by later -W options -Wall Turn on all warnings -Wparser Turn on parser warnings -Wlogic Turn on logic warnings (on by default) -Wdeprecated Turn on deprecation warnings (on by default) Options: * You can place any variable assignment in options and it will be * * processed as if it was in [files]. These assignments will be * * processed before [files] by default. * -o file Write output to file -d Increase debug level -t templ Overrides TEMPLATE as templ -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value -help This help -v Version information -early All subsequent variable assignments will be parsed right before default_pre.prf -before All subsequent variable assignments will be parsed right before [files] (the default) -after All subsequent variable assignments will be parsed after [files] -late All subsequent variable assignments will be parsed right after default_post.prf -norecursive Don't do a recursive search -recursive Do a recursive search -set <prop> <value> Set persistent property -unset <prop> Unset persistent property -query <prop> Query persistent property. Show all if <prop> is empty. -qtconf file Use file instead of looking for qt.conf -cache file Use file as cache [makefile mode only] -spec spec Use spec as QMAKESPEC [makefile mode only] -nocache Don't use a cache file [makefile mode only] -nodepend Don't generate dependencies [makefile mode only] -nomoc Don't generate moc targets [makefile mode only] -nopwd Don't look for files in pwd [project mode only]
I have tried running qmake -- MYSQL_PREFIX=/usr/include/mysql aswell but I get the same result.
I dont have any directory such as $QTDIR/qtbase/src/plugins/sqldrivers ...What should I do to build and install the driver for QMYSQL on ubuntu?
@SaadAli
Runningqmake
is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything viaapt
all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.I cannot remember precisely what you have fetch from
apt
to get all the necessary components (don't forget you can type e.g.apt install libmysql
and hit the Tab key twice to see available components). Do not proceed to anyqmake
steps. After yoursudo apt install libmysqlclient-dev
where are you in terms of runnability for a minimal program attempting to useQSql...
stuff? -
@SaadAli
Runningqmake
is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything viaapt
all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.I cannot remember precisely what you have fetch from
apt
to get all the necessary components (don't forget you can type e.g.apt install libmysql
and hit the Tab key twice to see available components). Do not proceed to anyqmake
steps. After yoursudo apt install libmysqlclient-dev
where are you in terms of runnability for a minimal program attempting to useQSql...
stuff?@JonB
I want to highlight according to the best of my knowledge that Qt Creator is normally installed byapt install qt5-default
but I usedsudo apt install qtcreator qtbase5-dev
because Ubuntu 22.04.2 LTS doesn't haveqt5-default
in its apt repository.Pressing Tab after typing
apt install libmysql
gives me the following options:libmysql++3v5 libmysqlcppconn-dev libmysql-ocaml libmysqlclient21 libmysql++-dev libmysql-ocaml-dev libmysqlclient-dev libmysql-diff-perl libmysqlcppconn7v5 libmysql++-doc
What should I install I have no idea.
After running
sudo apt install libmysqlclient-dev
I have achieved nothing. I get the same error when I printQSqlDatabase::lastError().text()
. The error is as the following:QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE "Driver not loaded Driver not loaded"
-
@SaadAli
Runningqmake
is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything viaapt
all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.I cannot remember precisely what you have fetch from
apt
to get all the necessary components (don't forget you can type e.g.apt install libmysql
and hit the Tab key twice to see available components). Do not proceed to anyqmake
steps. After yoursudo apt install libmysqlclient-dev
where are you in terms of runnability for a minimal program attempting to useQSql...
stuff?@JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:
I cannot remember precisely what you have fetch from apt to get all the necessary components
Try
apt install libqt
-Tab-Tab. I think you needlibqt5sql5-mysql
?Is there also a need for a
libqsqlmysql.so
? (Maybe that comes in the above package?) -
@JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:
I cannot remember precisely what you have fetch from apt to get all the necessary components
Try
apt install libqt
-Tab-Tab. I think you needlibqt5sql5-mysql
?Is there also a need for a
libqsqlmysql.so
? (Maybe that comes in the above package?)@JonB
Installinglibqt5sql5-mysql
made it work like a charm! Thank you @JonB ! That was all what I was missing.
But I don't know what is the role oflibqsqlmysql.so
. I dont know if installinglibmysqlclient-dev
made any difference. The only thing that happened after installing it was I got the filelibqsqlmysql.so
on my machine. -
-
@JonB
Installinglibqt5sql5-mysql
made it work like a charm! Thank you @JonB ! That was all what I was missing.
But I don't know what is the role oflibqsqlmysql.so
. I dont know if installinglibmysqlclient-dev
made any difference. The only thing that happened after installing it was I got the filelibqsqlmysql.so
on my machine.@SaadAli said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:
The only thing that happened after installing it was I got the file
libqsqlmysql.so
on my machine.Yep that's fine, it must be supplied in
libqt5sql5-mysql
package and that is what is needed.