Adding PostgreSQL support
-
Hey,
I'm currently having issues to get my old QT postgresql build working on a new pc.
It was once working on my old one but I simply can't remember the steps for it.
I went through the sqldriver tutorial https://doc.qt.io/qt-5/sql-driver.html, but as far as I remember I didn't build anything my self the last time.
Currently I've simply installed PostgreSQL on my Windows PCI've added follwing to my .pro
QT += core gui sql INCLUDEPATH += E:\Development\PostgreSQL\bin LIBS += E:\Development\PostgreSQL\lib
The QT seems to complain about the include paths, but VisualStudio seems to ignore that.
Now the strange thing is, When debugging through the app, it seems like it fails to open the DB connection and can't insert anything to my Database obviously.
And i get follwing debug output:
QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
But when I start the .exe directly through the windows explorer, everything works fine, which doesn't make any sense for me.
Can anyone help?
-
@Slei said in Adding PostgreSQL support:
E:\Development\PostgreSQL\bin
Are you sure this is the directory where include files are located?
It should be something like E:\Development\PostgreSQL\include -
yup thats correct, that was just something from my old project.
tbh, I don't even know if those lines have any affect at all, probably I don't even need those.
I also haven't seen any include/lib dir requirements in the tutorials.also libs has to be added with an -L prefix :
LIBS += -L"E:\Development\PostgreSQL\lib" -
Hi,
The PostgreSQL dlls are likely not found. Go to the Run part of the Project panel and add the path to them to the PATH environment variable.
-
@SGaist
I've added the postgresql lib path to the windows PATH env. variables already:postgresql install path "E:\Development\PostgreSQL\lib" and "E:\Development\PostgreSQL\bin"
additionally I've added those lines now to the "Run Environment" Path variable settings in "Run" bit it seems like still cannot load the drivers
The paths seem to work for executing the exe directly, since I can successfully execute sql stuff on the db, so maybe i'm still not adding the libs correctly
-
Ok, not sure if that was the issue at the end, but I've moved the settings from Accoun Environment Variables to System Variables and now it seems to work, even though the account variables are in the Qt Run Path...
About the Qt tutorial...
In there it says I have to build the drivers myself, but in the end, I never had to build anything at all, can anyone explain what this is for? Is it just for building qt from source?
For me this was quite confusing since it's the main tutorial that pops up when searching for "qt postresql tutorials" -
Which tutorial are you refereeing to ?
-
The pre-built binary comes with a set of drivers. What happens usually is that you have to tell your application where to find the corresponding dependencies. If the version of of PostgreSQL you installed is different that the one used to build the plugin, then you will have to re-build it.