V
V
Vsviridov902018-01-29 17:22:16
PostgreSQL
Vsviridov90, 2018-01-29 17:22:16

How to connect PSQL driver to Qt Creator project?

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 displayed on the request "qt build postgresql driver". The driver is still not going.
Most sources advise collecting in this way:

qmake"INCLUDEPATH+=C:\PostgreSQL\9.5\include""LIBS+="C:\PostgreSQL\9.5\lib\libpq.lib" psql.pro
mingw32-make

I get this error:
5a6f2d2dd7926893863723.jpeg
Console output when starting the project:
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 problem? How did you manage to win?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Furio, 2018-02-01
@Furio

I managed to solve it by throwing the libpq.dll file into the
{Path to Qt}Tools\mingw530_32\i686-w64-mingw32\lib
folder.
Only the dll that was in the folder of the installed PostreSql did not fit, I had to compile all the libraries from this article and take it from there libpq.dll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question