Important: Please read the Qt Code of Conduct -

Deploy application in windows with driver of postgresql

  • Hi,

    Everything works fine on my PC, I can connect to the postgresql driver.

    I have developed an application with c ++ and some files in qml, which connect to a postgresql database.
    I have compiled my executable with mingw73_64, which is what brings the installation of Qt 5.12.1.
    From my PC, I have tried to connect to a database that is regardless of the architecture, that is, I connect to a 32-bit postgresql 9.2 database, and a 64-bit postgresql 11 database, and everything works.
    When I try to deploy my application to be used on other PCs, I use this:

    windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>

    which is how it comes in the description of my qt. This generates all the dll associated with my application, but those of postgres are missing, so I have copied the following libraries found in the postgres installation:

    for 64 bit

    or for 32 bit, in case I connect to the 32 bit postgres database

    When I try to put these files on another PC, I get a driver not loaded error.

    and I have the postgres dll files mentioned, I have the sqldrivers folder with its qsqlpsql.dll dll, but it doesn't work for me.

    I tried with different dll but I don't get it.
    I tried to create my own library as it says in the version of qt

    cd% QTDIR% \ qtbase \ src \ plugins \ sqldrivers
    qmake - "PSQL_INCDIR = C: \ Program Files \ PostgreSQL \ 11 \ include" PSQL_LIBDIR = "C: \ Program Files \ PostgreSQL \ 11 \ lib \ ms"
    nmake sub-psql

    but when doing the qmake from the console of Qt 5.12.1 (MinGW7.3.0 64 bit)

    I am shown a list of the sql drivers but only those of SQLITE and ODBC are activated, but that of postgresql is not.

    What could be the problem that does not connect on other PCs, and on mine if it connects?

  • Lifetime Qt Champion

    Use Dependency Walker or similar to find out what the Qt postgres plugin really needs.

  • Lifetime Qt Champion


    Beside the good advice from @Christian-Ehrlicher, check also the PostgreSQL libraries dependencies.

  • It is possible that the qpsql library tells me that it depends on a libpq.dll that is not the one inside the application folder?


  • Lifetime Qt Champion

    Maybe a question of the architecture of the dll you copied.

    By the way, unless you added the folder containing the .dll in the search path of Dependency Walker, it will not find it because the plugin is in a different folder.

  • Before to update this programn, its work Fine with dlls of postgresql for 32 bit. This change could be the problem when i try to compile my programn, but this time with 64 bit?

  • Lifetime Qt Champion

    @MarlonBM You can't mix 32bit and 64bit in same application.

  • I get it.
    But the version of Qt 5.12.1 comes for 64 bit, and what it has done is compile everything to 64bit, with windeploy it takes all 64 bit dll.
    The application works for me, it starts, but the first thing I have is a login form, and when I try to use it, it gives me the driver not loaded error. That is why I think it is the postgres libraries that should be giving me problems.

  • Lifetime Qt Champion

    @MarlonBM You need 64bit PostgreSQL dll.

  • on the pc that I have the database,
    I have 2 versions of postgres installed, 9.2 of 32 bit, and 11 of 64 bit. I have stopped the postgresql service of the 32-bit one, in case they conflict. I have copied the dll that are in the bin folder of version 11 of 64 bit postgres, for my program folder and it still gives me the same error of
    "Driver not load"

  • Lifetime Qt Champion

    Again: are you sure that the correct dependencies are found ?

  • Hello,
    I have solved with the dependency walker tool,
    as advised by @Christian Ehrlicher and @SGaist.
    It was not a problem of the postgres dll but it was necessary to install mvcredistx64.

Log in to reply