📜 ⬆️ ⬇️

Qt driver assembly for working with PostgreSQL (Windows)

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:

When building Qt ( http://doc.qt.digia.com/4.7/configure-options.html ) the following options are responsible for this

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:
  1. Start Qt command line (Start-> Programs-> Qt by Digia ...-> Qt xxx Command Promt)
  2. Configuring the source and including the necessary driver as a plugin
    configure -I "c:\psql\include" -L "c:\psql\lib" -plugin-sql-psql
  3. cd src\plugins\sqldrivers\psql
  4. qmake psql.pro
  5. make debug
  6. make release

We are checking% QTDIR% \ plugins \ sqldrivers. Bingo!

Source: https://habr.com/ru/post/173283/


All Articles