MySQL Support in Qt5.2.1 on Ubuntu
-
Hi
I'm new to Qt and quite new to linux. I'm trying to use Qt and link to a mysql database. I'm having difficulty installing Qt using the correct method. I gather that because its 5.2 I have to build it from source.
I've used this command:
@ ./configure -opensource -confirm-license -gui -widgets -qt-sql-mysql -plugin-sql-mysql ^C@and then have run
@make -j5@
@sudo make install@However after the install, I cannot find the Qt creator IDE. Apparently it is part of the source files, does it not get build automatically, or do I need to install it separately?
Thanks
-
Hi and welcome to devnet,
Qt Creator is not part of Qt's sources, you have to either install it manually or compile it yourself. You can find it pre-compiled on the download page.
You don't need to rebuild Qt completely to create the MySQL plugin. You can use the source (take the same as the binary Qt version) and follow the instructions from there.
Note that with the configuration options you are giving, you are trying to build Qt with MySQL support builtin and as plugin which doesn't make sense.
-
Thanks so much.
I have managed to get it working, I'm just going to list the steps I followed to make it easier for others.
Installing Qt with Qmysql on Ubuntu (http://qt-project.org/doc/qt-5/linux-building.html)
Type in the terminal:
@sudo apt-get install libqt5sql5-mysql libmysqlclient18 libmysqlclient-dev libmysql++-dev build-essential cmake mysql-client mysql-server @You might need to install other packages depending on the current state of your system.
Download the binaries for Qt 5.2.1 and unpack them to your home directory.
@cd qt-everywhere-opensource-src-5.2.1
./configure -opensource -confirm-license -gui -widgets -qt-sql-mysql
make
sudo make install@go to home directory by typing @cd@
type
@gedit .profile@and insert at the end of the file:
@PATH=/usr/local/Qt-5.2.1/bin:$PATH
export PATH@Save and Close.
@gedit .login@
insert
@setenv PATH /usr/local/Qt-5.2.1/bin:$PATH@
at the end of the file.
Save and Close.Reboot your computer.
Download Qt Creator 3.1.0 for Linux
unpack to the home directory@cd qt-creator-opensource-src-3.1.0@
@qmake -r
make@You will find qtcreator in "home/qt-creator-opensource-src3.1.0/bin" and double clicking this will open Qt Creator.
Add to your .pro file in a project:
@QT += sql@
Add to your main.cpp file:
@#include <QtSql>@
you should be able to create a database object using:
@QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");@
-
Why libqt5sql5-mysql if you are using your own Qt ?
-
Hi,
This thread seems like it is getting close to an actual solution to what seems a common difficulty -- getting mysql support within Qt 5.
So, my question of SGaist, is how would you install Qt and Mysql to get them to work together. I have once again started all over with reinstalling Ubuntu (14.04) and now I really want a single path toward getting Qt to talk to Mysql.
Would you omit the install libqt5sql5-mysql above and do the rest? If so, where do the mysql parts come from?
Val
San Juan Island, WA -
libqt5sql5-mysql this pulls in the distribution's Qt 5 MySQL plugin which is not the one you want.
You need to install the MySQL dev package to have the files needed to build the plugin (same as you need the OpenGL dev package for the OpenGL part of Qt).
That's pretty much all