Ubuntu and QT5 connect to MySQL and ubuntuqt5mysql

Source: Internet
Author: User

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)

  • Make
  • Sudo make install

PS: if the "mysql. h" file is not found, install "mysql-libmysqlclient-dev"

  • Sudo apt-get install 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.