Connecting the PSQL Qt Creator driver

Available:

1.Windows 7 64bit;

2.PostgreSQL 9.5 32bit;

3.Qt Creator 4.5;

4.Qt lib 5.10.0;

5.MinGW 5.3.0 32bit

Task: connect the PSQL driver to the Qt project.

I have already tried all the methods that are output by the query "qt build postgresql driver". The driver is still not going to be built.

Most sources advise collecting this way: qmake"INCLUDEPATH+=C:\PostgreSQL\9.5\include""LIBS+="C:\PostgreSQL\9.5\lib\libpq.lib" psql.pro mingw32-make

I get this an error: Error after executing mingw32-make

Console output at project startup:

Available drivers: ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7") QSqlDatabase: QPSQL driver not loaded

. pro file:

QT -= gui
QT += sql
QT += core

CONFIG += c++11 console
CONFIG -= app_bundle
QT_DEBUG_PLUGINS = 1

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += main.cpp

Main.cpp:

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <iostream>
#include <QSqlDriver>
#include <QSql>
#include <QtSql>


using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL7");
    db.setHostName("188.120.232.***");
    db.setDatabaseName("postgres");
    db.setUserName("postgres");
    db.setPassword("123");
    if (!db.open()) {
        cout«"Crash "«endl;
    }
    else
        cout«"Ok"«endl;
    return a.exec();
}

Who faced such a problem? How did you manage to win?

Author: gil9red, 2018-01-29

2 answers

I managed to solve it by throwing it in a folder {Path to Qt}Tools\mingw530_32\i686-w64-mingw32\lib file libpq.dll

Only the dll that was in the folder of the installed PostreSQL did not fit, I had to compile all the libraries according to this article and take it from there libpq.dll

 1
Author: Дмитрий Денисов, 2018-02-01 07:53:16

Watch this video Compiling the driver for the PostgreSQL DBMS. Maybe it will help you.

 0
Author: Compozitor, 2018-01-30 09:39:30