PostgreSQL and Trying to connect using Qt
-
wrote on 9 Feb 2014, 19:54 last edited by
...
just build libpq.a from sources . . . .
http://pgolub.wordpress.com/2008/12/15/building-postgresql-client-library-using-mingw-under-winxp-sp3/don't know what to do with it.
sorry for by n00bness, people... -
wrote on 9 Feb 2014, 19:54 last edited by
It is not necessary to compile postgresql, I used the binaries 32-bit and with installing ./lib and ./include had been provided, too.
Your make does not recognise the psql includes (the stuff, that follows -I) and that's why you still receive the message 'libpq-fe.h not found'.
Do you see the same error if you use backslashed paths with you qmake command? Qt uses forward slashes but I had success with the backslashed command. -
Just to be sure, wouldn't by any chance libpq-fe.h be in include/libpq ? If so it's that last element that was missing.
-
wrote on 9 Feb 2014, 21:59 last edited by
Yes, this has been installed in "C:\Program Files (x86)\PostgreSQL\9.3\include" together with the binaries of PostgeSQL 32-bit:
"03.12.2013 06:13 21.082 libpq-fe.h"
and - the PostgreSQl include has to be added to qmake! -
Indeed, but you need to give the full path to libqp-fe.h not just the path that contains the libpq folder.
Please avoid having spaces in your path when developing, it something that is not working very well on windows
-
wrote on 10 Feb 2014, 11:27 last edited by
on my system i installed postgreSQL x86 9.3 to c:\psql93_x86\
so... the qmake command where i specify the INCLUDE+=, LIBS+= etc . . .
i need to tell it precisely and exactly where libqp-fe.h is, including full path ?how do I do that, i.e. what separator do i use to add more than one entry into the "INCLUDE+=" that i've already specified (using clochydd's tuto on page 2. .) ?
-
wrote on 10 Feb 2014, 11:37 last edited by
Go to the Qt plugin source directory:
cd QT_SRC_PATH\src\plugins\sqldrivers\psqlStart building the plugins:
(Change this to your mingw32 path: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin)
C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin\qmake “INCLUDEPATH+=c:\psql93_x86\include”
“LIBS+=c:\psql93_x86\lib\libpq.lib” psql.pro -
libpq-fe.h being in include/libpq
You should use
@“INCLUDEPATH+=c:/psql93_x86/include/libpq”@
-
wrote on 10 Feb 2014, 17:34 last edited by
same :(
-
wrote on 10 Feb 2014, 18:19 last edited by
Don't give up - we will find a solution, hopefully!
- Is the qmake error message concerning the libpq-fe.h exactly as before?
- Could you please post the message again?
- Could you post the directory list of c:\psql93_x86\include?
-
wrote on 10 Feb 2014, 18:39 last edited by
just tried making the odbc driver again...
and get the Driver not Loaded message :)
C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>c:\Qt\5.2.1\mingw48_32\bin\qm
ake.exe "INCLUDEPATH+=c:/psql93_x86/include/libpq" "LIBS+=c:/psql93_x86/lib/libp
q.lib" psql.proC:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>mingw32-make debug
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldrive
rs/psql'
g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -fno-exceptions -frtti -Wa
ll -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEP
TIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I"C:\Qt\5.2.1\mingw48_32\inclu
de\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.
2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1
mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1
QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........
mkspecs\win32-g++" -o .obj\debug\qsql_psql.o ......\sql\drivers\psql\qsql_psql
.cpp
......\sql\drivers\psql\qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No such
file or directory
#include <libpq-fe.h>
^
compilation terminated.
Makefile.Debug:497: recipe for target '.obj/debug/qsql_psql.o' failed
mingw32-make[1]: *** [.obj/debug/qsql_psql.o] Error 1
mingw32-make[1]: Leaving directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldriver
s/psql'
makefile:48: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2 -
wrote on 10 Feb 2014, 19:17 last edited by
http://pastebin.com/4cpqVMiN
folder contents -
wrote on 10 Feb 2014, 21:27 last edited by
Thanks for the data! I can see our "fatal" libpq-fe.h in c:\psql93_x86\include. So as a first step I suppose to test with:
C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>c:\Qt\5.2.1\mingw48_32\bin\qmake.exe “INCLUDEPATH+=c:\psql93_x86\include” “LIBS+=c:\psql93_x86\lib\libpq.lib” psql.pro
I know, the backslashes are a bit unusual for Qt but it worked with my installs so give it a try! Good luck! -
wrote on 12 Feb 2014, 14:34 last edited by
i've tried on many occasions with \ and /: same result.
The problem is obviously over my level of unkludging, and I've figured out how to use ODBC instead.
@
#include <QtSql>
#include <QString>
#include <QSqlDatabase>void connect_db()
{QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
QStringList driversList = QSqlDatabase::drivers();
qDebug() << "drivers list= " << driversList;
bool bOpen(false);
db.addDatabase("QODBC","odbcname");
db.setHostName("localhost");
db.setDatabaseName("dbname_in_postgres");
db.setUserName("username");
db.setPassword("password");
bOpen =db.open();
QString str=db.lastError().text();
}@str remains empty :)
and bOpen shows True for the first time in a month's trying.
I dont need pure pg connection, using an ODBC is fine for me at this stage.
Now for trying to make my DAO classes :)
thanks to all for helping, sorry it didn't work out as intended, but for ODBC connections, my above code works. -
wrote on 29 Aug 2015, 22:09 last edited by
Hello!
What did you put for this line:
db.addDatabase("QODBC","odbcname");
Not sure what to put instead of odbcname.
Thanks!
-
wrote on 30 Aug 2015, 08:21 last edited by
Hello Duncan,
if you only open one database, you do not need to specify the connection name:
db.addDatabase("QODBC");
If you plan work with more connections, use a name to identify each connection:
db.addDatabase("QODBC","myConn1");
-
Hi,
addDatabase is a static function that returns a QSqlDatabase instance that will use the selected backend.
So you must call it like that:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC")
The suggestion of @clochydd about the connection name still applies.