Solve the Problem of connecting Qt to PostgreSQL in Ubuntu

Source: Internet
Author: User
Tags psql
I encountered a problem yesterday and had not solved it for a day. Today, I suddenly solved it. The problem is: in Windows, you need to manually compile the PostgreSQL driver in the Qt source code to connect to PostgreSQL, then, place the generated dynamic Connection Library to the plug-in directory plugins in the installation directory of Qt. when I ran to Ubuntu, I found that in my qt4.8.6 directory/opt/qt4.8.6/plugins/sqldriv

I encountered a problem yesterday and had not solved it for a day. Today, I suddenly solved it.

The problem is: in Windows, you need to manually compile the PostgreSQL driver in the Qt source code to connect to PostgreSQL, then, place the generated dynamic Connection Library to the plug-in directory plugins in the installation directory of Qt. when I ran to the Ubuntu system, I found that libqsqlite exists in my qt4.8.6 directory/opt/qt4.8.6/plugins/sqldrivers. so and libqsqlpsql. so, that is, qt already comes with the PostgreSQL driver. then, after directly compiling the project, the runtime prompts that the database driver is not found, and not only the psql driver is not found, but the basic sqlite driver is not found.

I am so depressed that the driver is clearly there. Why did I say no?

I installed qt5.2.1 in my system, and I tried to re-compile and run it on 5.2.1. I found that only the sqlite driver was found, but the psql driver was not found. I ran to its plugins/sqldrivers directory and found that only libsqlite exists. so.

So the question is: qt5.2.1 found the sqlite driver. Why can't qt4.8.6 be found?

I always think that there is a problem with the link path during compilation, but it cannot be solved.

Until today, I have rewritten and enabled qtcreator to directly run the program and found that the program is connected to the database! Then I overwrite the compilation and say no database driver is found! Why? Later, after a while, I found that I directly compiled it under qt4.8.6 and executed it under qt5.2.1. Then the link was successfully linked. then I tried to directly run the execution file built by qt4.8.6 on the terminal, and the link was successful.

It turned out to be a dynamic link library issue during runtime, rather than a compilation issue!

Originally in the Run Environment of Qt, the LD_LIBRARY_PATH of qt4.8.6 is automatically set to/opt/qt4.8.6/lib and changed to/opt/qt4.8.6. the required dynamic library is actually in/opt/qt4.8.6/plugins/sqldrivers.

The running environment of qt5.2.1 can run because the LD_LIBRARY_PATH of qt5.2.1 is automatically set to/usr/lib/x86_64-linux-gnu, and there is another qt4 directory under this directory, the libsqlite. so.

I have discovered this silly problem for so long.

------------------------------------ Lili split line ------------------------------------

Install PostgreSQL 6.3 http://www.linuxidc.com/Linux/2014-05/101787.htm in CentOS 9.3 environment yum

PostgreSQL cache detail http://www.linuxidc.com/Linux/2013-07/87778.htm

Windows platform compiling PostgreSQL http://www.linuxidc.com/Linux/2013-05/85114.htm

Configuration and installation http://www.linuxidc.com/Linux/2013-04/83564.htm of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu

Install and configure the http://www.linuxidc.com/Linux/2011-08/40520.htm for phppgAdmin on Ubuntu

Install PostgreSQL9.3 http://www.linuxidc.com/Linux/2014-05/101723.htm on CentOS Platform

PostgreSQL configure Streaming Replication cluster http://www.linuxidc.com/Linux/2014-05/101724.htm

How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4Http://www.linuxidc.com/Linux/2014-12/110108.htm

------------------------------------ Lili split line ------------------------------------

PostgreSQL details: Click here
PostgreSQLOf: Click here

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-01/111678.htm

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.