Ubuntu and QT5 connect to MySQL and ubuntuqt5mysql
To connect to MySQL using QT, you need to share the driver of libqsqlmysql. so. The path is under the plugin/sqldrivers directory. At first glance, it is available, but it is not.
Use the ldd command to analyze libmysqlclient_r.so. * => not found. Later, libmysqlclient_r.so. * is obviously missing another shared library. They are dependent and solve this problem to connect QT to the MySQL database. The version of the shared library under my/usr/lib64/is higher than that of libmysqlclient. so.18. I thought of a speculative idea to create a symbolic link using ln. However, this is useless.
PS: ldd: analyzes and prints the shared library files that executable files depend on in linux.
I can't help but laugh at the fact that QT5.5 was downloaded from the official website. It depends on a lower version. You can't help but be lazy during compilation. It is estimated that they copied libqsqlmysql directly from a lower version. so, no way? Apparently not. Open the qt official website to download the source code and compile it by yourself. Download process skipped, very good to find the http://download.qt.io/official_releases/qt/5.5/5.5.1/submodules/ (no source code qt5.5), find the qtbase about 60 M. The path of the MySql driver is qtbase/src/plugins/sqldrivers/mysql /.
- Qmake "INCLUDEPATH + =/usr/include" "LIBS + =-L/usr/lib-lmysqlclient_r" mysql. pro
(Include is the location of the header file "mysql. h". You can find it using "sudo find-name" mysql. h ". lib is the location of the shared library)
PS: if the "mysql. h" file is not found, install "mysql-libmysqlclient-dev"
Enter "SQL Database Drivers" in the help manual of QT to view the connection mode of other databases.
In this way, you can connect to the MySQL database.
References:
Connection to MySQL database (driver not loaded) with QT5.5 in CentOS7 (64-bit)
Fatal error: mysql/mysql. h: No such file or directory solution