Small lyrical digression:
Write this note I was inspired by the presence on the Internet of a huge number of instructions that simply cite the documentation, but do not really work. Since I work with Qt from time to time, I don’t know how things are with this problem in Qt5.Problem
The default installation (at least for version 4.8.4) is not included in the driver for working with Postgres.
The official documentation suggests collecting it in a very simple way
http://qt-project.org/doc/qt-4.8/sql-driver.html#qpsql , but if you downloaded the already assembled Qt, you will be pretty puzzled that the build takes place without errors, but nothing works.
Qt and SQL
Here it is necessary to go deep into the specifics of working with the sql drivers in Qt. Perhaps two options for their implementation:
- embedding the driver in the QtSql library
- driver compilation as plugin
When building Qt (
http://doc.qt.digia.com/4.7/configure-options.html ) the following options are responsible for this
- -qt-sql- <driver> Enable a SQL <driver> in the Qt Library.
- -plugin-sql- <driver> Enable SQL <driver>
You can see which drivers in your installation are assembled as plugines along this path:
%QTDIR%\plugins\sqldrivers
Decision
And now we come to the essence of the problem and its simple solution.
As far as I understand, by default, SQL drivers are collected statically, i.e. for linking with QtSql. Therefore, as a result of the assembly according to the documentation, we only get * .a files that cannot be attached to the existing QtSql4.dll. The solution that is often found on the network is to rebuild Qt entirely by including the necessary drivers in the configuration. In principle, the option is normal, but only very long.
Naturally, we can manually fix makefiles and build the necessary driver as a plugin, but this is a thankless task - let the computer do it for us.
')
Further it is assumed that PostgreSQL with the necessary libraries and header files is installed in C: \ psql (I usually put it in Program Files, and C: \ psql is a junction).
Well, then everything is quick and simple:
- Start Qt command line (Start-> Programs-> Qt by Digia ...-> Qt xxx Command Promt)
- Configuring the source and including the necessary driver as a plugin
configure -I "c:\psql\include" -L "c:\psql\lib" -plugin-sql-psql
cd src\plugins\sqldrivers\psql
qmake psql.pro
make debug
make release
We are checking% QTDIR% \ plugins \ sqldrivers. Bingo!