PDA

View Full Version : QT to Postgresql connection



KeithN
6th November 2011, 23:42
I am trying to rewrite a manufacturing system I wrote years ago in WatcomSQL. I want to use QT 4.7 and Postgres 9.1. I've been trying for days to create the connection and don't want to give up but I need help. Nothing I try works. I have tried to execute the instructions on the nokia site as well as others to no avail.

I really want this to work and am determined not to give up. Can anyone patiently take me through the steps? I am using windows xp. I have Postgres installed on my network. I can access any database in Postgres from any other machine on my network. I need help on the QT side mostly. I can get examples up and running using QSQLITE so QT is running properly.

Thanks in advance

ChrisW67
7th November 2011, 00:19
Have you built the Postgres (QPSQL) plugin for Qt? Does QPSQL appear in the output of QSqlDatabase::drivers()?

KeithN
7th November 2011, 00:44
Not successfully. I think you are referring to this?

cd %QTDIR%\src\plugins\sqldrivers\tds
qmake -o Makefile "LIBS+=NTWDBLIB.LIB" tds.pro
nmake

One thing is I have no nmake.exe

Added after 8 minutes:

Pardon me, I meant this code:

cd %QTDIR%\src\plugins\sqldrivers\psql
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
nmake

ChrisW67
7th November 2011, 03:19
"nmake" is the Microsoft compiler suite make utility. If you are using the bundled MingW then substitute "mingw32-make".

KeithN
7th November 2011, 04:54
Thanks, I got the first line:
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
to run without errors. I now have a bunch of files in the plugins\sqldrivers\psql folder:
main.cpp
Makefile
Makefile.Debug
Makefile.Release
psql.pro
psql.pro.user
qsqlpsql_resource.rc
qsqlpsqld_resource.rc

When I run ming32-make I get all kinds of errors
pg_config.h No such file or directory
"XXXXXXXXX was not declared in this scope" errors after that

ChrisW67
7th November 2011, 06:04
The paths in this command:


qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro

must match the location of your Postgres installation in order that the compiler can find the include files (like the example you give) anf\d libraries (when you get that far).

KeithN
7th November 2011, 15:05
I felt like I had the right path for the qmake -

Postgres is installed in
Directory of C:\Program Files\PostgreSQL\9.1

11/03/2011 02:08 PM <DIR> .
11/03/2011 02:08 PM <DIR> ..
11/03/2011 02:05 PM <DIR> bin
11/06/2011 08:27 PM <DIR> data
11/03/2011 02:05 PM <DIR> doc
11/03/2011 02:05 PM <DIR> include
11/03/2011 02:06 PM <DIR> installer
11/03/2011 02:06 PM <DIR> lib
11/03/2011 02:06 PM <DIR> pgAdmin III
11/03/2011 02:06 PM <DIR> scripts
11/03/2011 02:06 PM <DIR> share
11/03/2011 02:05 PM <DIR> StackBuilder
11/03/2011 02:06 PM <DIR> symbols

qtsdk is installed in:

Directory of C:\QtSDK\QtSources\4.7.4

11/03/2011 03:43 PM <DIR> bin
11/03/2011 03:42 PM <DIR> lib
11/03/2011 03:43 PM <DIR> mkspecs
11/03/2011 03:44 PM <DIR> qmake
11/06/2011 10:48 PM <DIR> src
11/03/2011 03:44 PM <DIR> tools
11/03/2011 03:44 PM <DIR> translations
11/03/2011 03:43 PM <DIR> util

using this template:
cd %QTDIR%\src\plugins\sqldrivers\psql
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
ming32w-make
I went to the qt desktop mingw 4.7.2 command window:
the command I used was:
cd C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ps ql
qmake -o Makefile "INCLUDEPATH+=C:\QtSDK\QtSources\4.7.4\src\plugins\ sqldrivers\psql\include" "LIBS+=C:\Program Files\PostgreSQL\9.1\lib\ms\libpq.lib" psql.pro

This came back to the command prompt with no messages

Then running min32w-make all hell broke loose with no include files in path

Still determined to make it work. Incidentally I have XTUPLE installed which uses qt and postgres. Can I use the driver qsqlpsql4.dll to connect? Maybe I have to install Postgresql 8.3 and the QT version to match. I'd rather get this figured out. Its becoming a matter of principle now :) Thanks

PS I forgot to add that I constructed the qmake line with double backslashes as in:

qmake -o Makefile "INCLUDEPATH+=C:\\QtSDK\\QtSources\\4.7.4\\src\\plu gins\\sqldrivers\\psql\\include" "LIBS+=C:\\Program Files\\PostgreSQL\\9.1\\lib\\ms\\libpq.lib" psql.pro

Regards, Keith

ChrisW67
7th November 2011, 21:52
Your INCLUDEPATH is still wrong.


qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
# The Postgres includes ^^^^^ and libraries ^^^^^^^

Notice that this points to the includes that come with Postgres and not anything to do with Qt as you are doing now.

Try


qmake -o Makefile "INCLUDEPATH+=C:\Program Files\PostgreSQL\9.1\include" "LIBS+=C:\Program Files\PostgreSQL\9.1\lib\ms\libpq.lib" psql.pro


You may still have issues with the space in the paths.

KeithN
8th November 2011, 01:02
Thanks, I'll try that ASAP. I am assuming that the psql.pro at the end is just a target name for the qmake to create and that it will create it in the directory that I cd'd to in the first line of the shell?

ChrisW67
8th November 2011, 02:01
No, psql.pro is a supplied part of the Qt that is already present. It is the input to qmake, and the output is specified as Makefile.

KeithN
8th November 2011, 02:14
I'm sorry, I guess I "knew" that. It is a QT supplied file in the plugins path. I've been working with a programmer going over the outline of the system that we will rewrite. I will try this tomorrow. I really appreciate your patience and willingness to help me through this. I'm sure that this problem for me will seem simple when solved.

Thanks again and I will post the result.

KeithN
8th November 2011, 16:30
OK, today I ran the commands per your suggestion and the qmake seemed to run fine. The mingw32-make looked good (although it was pretty verbose). I ended up with these sets of files:

Directory of C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ps ql

11/08/2011 11:22 AM <DIR> .
11/08/2011 11:22 AM <DIR> ..
11/08/2011 10:52 AM <DIR> debug
11/03/2011 03:43 PM 2,564 main.cpp
11/08/2011 10:41 AM 7,187 Makefile
11/08/2011 10:41 AM 7,570 Makefile.Debug
11/08/2011 10:41 AM 7,421 Makefile.Release
11/03/2011 03:44 PM 119 psql.pro
11/04/2011 04:09 AM 21,280 psql.pro.user
11/08/2011 10:41 AM 639 qsqlpsqld_resource.rc
11/08/2011 10:41 AM 637 qsqlpsql_resource.rc
11/03/2011 03:42 PM 209 README
11/08/2011 10:41 AM <DIR> release

and

Directory of C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ps ql\debug

11/08/2011 11:23 AM <DIR> .
11/08/2011 11:23 AM <DIR> ..
11/08/2011 10:52 AM 2,182 libqsqlpsqld4.a
11/08/2011 10:52 AM 167,577 main.o
11/08/2011 10:52 AM 3,344 moc_qsql_psql.cpp
11/08/2011 10:52 AM 162,198 moc_qsql_psql.o
11/08/2011 10:52 AM 887,007 qsqlpsqld4.dll
11/08/2011 10:52 AM 624 qsqlpsqld_resource_res.o
11/08/2011 10:52 AM 374,956 qsql_psql.o

What is my next step? Thanks

ChrisW67
8th November 2011, 21:09
Uh, use it?! You have built the QPSQL plugin and should be able to see it in the output of QSqlDatabase::drivers(). Use QSqlDatabase::addDatabase() with "QPSQL" as the type, set the host, user name, and password...

KeithN
9th November 2011, 00:20
I'm using an example that does run with QSQLITE and I replace the connect code with:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setDatabaseName("postgres");
db.setHostName("localhost");
db.setUserName("admin");
db.setPassword("admin");
db.setPort(5433);

Then I get this in the debug window:

Starting C:\QtSDK\Examples\4.7\qt-book\chap13\staffmanager-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug\debug\staffmanager.exe.. .
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
C:\QtSDK\Examples\4.7\qt-book\chap13\staffmanager-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug\debug\staffmanager.exe exited with code 1

I put the qsqlpsqld4.dll file in the directory C:\QtSDK\QtCreator\bin\sqldrivers (where I find the qsqllite4.dll also)

I will keep trying but appreciate any insight you may have. Keith

ChrisW67
9th November 2011, 01:05
Run "mingw32-make install" in the directory you built the plugin in to install all the bits (debug and release) into the correct Qt locations.

You also have to have the Postgres dynamic libraries where the system can find (on the PATH) them or it will fail when the plugin cannot be loaded for lack of its dependencies.

KeithN
9th November 2011, 03:12
OK, I ran the mingw32-make install and it finished. It tried to copy /y qsqlpsqld4.pdb to c:\qtsdk\desktop\qt\4.7.4\mingw\plugins\sqldrivers and came back with The system cannot find the file specified. The next line said mingw32-make[1]: [install_target] Error 1 (ignored)
Next it successfully copied debug\qsqlpsqld4.dll to c:\qtsdk\desktop\qt\4.7.4\mingw\plugins\sqldrivers

So...when you say "You also have to have the Postgres dynamic libraries where the system can find (on the PATH) them" Do you mean the postgres C:\Program Files\PostgreSQL\9.1\lib ?
and then are you speaking of the path I get when I shell and type path?
Current path is:
PATH="C:\Program Files\PostgreSQL\9.1\bin";C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin;C:\QtSDK\ming w\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\Sy stem32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Common Files\HP\Digital Imaging\bin;C:\Program Files\HP\Digital Imaging\bin\;C:\Program Files\HP\Digital Imaging\bin\Qt\Qt 4.3.3;

Added after 34 minutes:

Pardon me. The path I quoted before is from the command shell I compiled under. The path in a normal command shell doesn't have any qt or postgres paths in it. Sorry for my ignorance, but how do I put the C:\Program Files\PostgreSQL\9.1\lib on the path for QT? I'll try putting it on the system path for now. Thanks

Added after 7 minutes:

I added 9.1\lib to the system path and tried again - still no QPSQL driver. I'll keep trying.

thefatladysingsopera
9th November 2011, 11:13
Hello,i ran into so many problems myself compiling sql drivers but i finally managed to somehow compile successfully.I have attached a file containing firebird,mysql and postgres drivers hoping they will save you sometime.To make the mysql and postgres drivers work for you,you must put the bin directory in the environmental variables for instance in postgres,i have C:\psql\bin since i installed postgres in c:\psql.In mysql find the bin directory and place it in your environmental variables too.You don't have to put the bin dir for firebird in the environmental variables.

When deploying your application,say using postgres,you must place qsqlpsql4.dll in a folder sqldrivers and should reside in the same directory as your executable.

Hope that helps.


UPDATE: All drivers(release and debug) are now available on sourceforge: https://sourceforge.net/projects/qtdrivers/

KeithN
9th November 2011, 13:26
Thanks so much. I will give these a try. When you say "same directory as your executable." do you mean qtcreator.exe as in C:\QtSDK\QtCreator\bin

Keith

thefatladysingsopera
9th November 2011, 14:12
What i meant was,when you are done making your application and you want to distribute it,you will have (the application(example.exe,all the needed dlls i.e QtCore4.dll etc inside a folder lets say called,my_application.Inside the folder my_application,you will have to make a folder sqldrivers and put in it the dll qsqlpsql4.dll if your application uses postgres.

This post explains it sufficiently http://www.qtcentre.org/threads/12498-SQlite-driver-not-loaded-error

KeithN
9th November 2011, 16:03
Thanks much. It looks like the connection is working. In the sample app I loaded and ran the new table that was supposed to be created and populated wasn't created but the data window opened and no errors so I go to the next step. Thanks again. I have been trying so long to get this working and it seems like wasted time however I have been absorbing a lot too. And thanks to Chrisw67 I did get the plugin to compile - so foreign to me to deal with this environment vis. the WatcomSQL that worked seamlessly and allowed me to get right to work. However I am very excited to be learning QT and know that in the end I will be a much more effective developer.

Regards, Keith

KeithN
9th November 2011, 23:57
..........

KeithN
10th November 2011, 03:22
Everything working now. Thanks again.

Jeewes87
28th November 2011, 21:01
Hi. I'm still fighting with this problem.

I downloaded those drivers (from the link) and put those into "E:\QtSDK\Desktop\Qt\4.7.4\mingw\plugins\sqldrivers" -directory. After that I put "C:\psql\9.1\bin;" into system variable PATH. After that I restarted Nokia Qt Creator and pressed run my project and the result was still: QSqlDatabase:
QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE

This is though. I have fought and fought with this problem and it's still beating me. So please, I need help. Thank you.

Jeewes87
30th November 2011, 17:54
Wohoo!! I solved the problem. I had 64bit version of the postgreSQL and 32bit-version was the one I should have used. Changeing the psql version solved the problem.

So overall what I did to get the psql plugin work in my QtSDK:

1. I downloaded psql drivers from the previously mentioned link. (You can also create those by your self incase url is not available).
2. I added those driver files into "E:\QtSDK\Desktop\Qt\4.7.4\mingw\plugins\sqldriver s" -directory.
3. I added "C:\psql\bin;" (and just to make it sure also "C:\psql\lib;C:\psql\include;") to my PATH system variable.
4. Finally started Qt creator and tested my code... ..and vóla!

Thank's everyone.

CyrilQt
27th May 2012, 12:02
Good day everyone,

I still encounter trouble with the QSPQL driver.
Until the #13 post, everything worked fine.
I followed these steps according to:
http://www.qtcentre.org/wiki/index.php?title=Building_the_QPSQL_plugin_on_Windo ws_using_MinGW;

-Go to %QTDIR%/src/plugins/sqldrivers/psql. (for me: D:\Qt\2010.05\qt\src\plugins\sqldrivers\psql)
-Run the following command: qmake -o Makefile "INCLUDEPATH+=C:\PostgreSQL\8.3\include" "LIBS+=C:\PostgreSQL\8.3\lib\libpq.a" psql.pro
NB:I wrote: "qmake -o Makefile "INCLUDEPATH+=D:\PostgreSQL\include" "LIBS+=D:\PostgreSQL\lib\libpq.a" psql.pro" in order to match the correct destination.
-Run make - this should build the qsqlpsql.dll and libqsqlpsql.a files in the %QTDIR%/plugins/sqldrivers directory. (where i ran :mingw32-make.)


at this point i got in %QTDIR%/src/plugins/sqldrivers/psql


11/02/2012 15:46 <REP> .
11/02/2012 15:46 <REP> ..
26/05/2012 23:34 2*873 main.cpp
10/09/2010 10:05 514 psql.pro
10/09/2010 10:05 215 README
25/05/2012 19:09 781 qsqlpsqld_resource.rc
25/05/2012 19:09 <REP> tmp
25/05/2012 19:09 780 qsqlpsql_resource.rc
25/05/2012 19:09 24*845 Makefile.Debug
25/05/2012 19:09 24*693 Makefile.Release
25/05/2012 19:09 6*122 Makefile

I this point I noticed that I had no debug or release directory at all whereas it is the case in this discussion.

Meanwhile:
%QTDIR%/src/plugins/sqldrivers/psql>dir


11/02/2012 15:47 <REP> .
11/02/2012 15:47 <REP> ..
13/09/2010 06:16 2*168 libqsqlite4.a
13/09/2010 06:16 2*178 libqsqlited4.a
13/09/2010 06:17 2*178 libqsqlodbc4.a
13/09/2010 06:17 2*182 libqsqlodbcd4.a
13/09/2010 06:17 478*720 qsqlite4.dll
11/02/2012 15:56 1*736*365 qsqlited4.dll
13/09/2010 06:17 163*840 qsqlodbc4.dll
13/09/2010 06:17 971*676 qsqlodbcd4.dll
27/05/2012 12:16 889*883 qsqlpsqld4.dll
27/05/2012 12:16 2*182 libqsqlpsqld4.a
27/05/2012 12:16 123*392 qsqlpsql4.dll
27/05/2012 12:16 2*178 libqsqlpsql4.a

At this point, i have a test program:


#include<QApplication>
#include<QtSql/QSqlDatabase>
#include<QDebug>
#include<QtGui>

int main(int argc, char *argv[])
{

QApplication a(argc, argv);
QSqlDatabase bd = QSqlDatabase::addDatabase("QPSQL");
qDebug() << QSqlDatabase::drivers();
return a.exec();
}


and a .pro like this:
QT+=sql

SOURCES += \
main.cpp

Still nothing is working ouput:


Démarrage de E:\cyril ***\Mes documents\Projets_Qt\test_connect_postgres1-build-desktop\debug\test_connect_postgres1.exe...
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
("QSQLITE", "QODBC3", "QODBC")
E:\cyril ***\Mes documents\Projets_Qt\test_connect_postgres1-build-desktop\debug\test_connect_postgres1.exe s'est terminé avec le code 1

I'm not sure how to set correctly the right PAHT variable so i did like this inside the Qtenv.bat (or Qtvar.bat) name differs for a reason i ignore.


@echo off
rem
rem This file is generated
rem
echo Setting up a MinGW/Qt only environment...
echo -- QTDIR set to D:\Qt\2010.05\qt
echo -- PATH set to D:\Qt\2010.05\qt\bin
echo -- MINGW set to D:\Qt\2010.05\qt\mingw
echo -- lib set to D:\Qt\2010.05\qt\lib;D:\Qt\2010.05\mingw\lib
echo -- include set to D:\Qt\2010.05\qt\include;D:\Qt\2010.05\mingw\inclu de
echo -- Adding D:\Qt\2010.05\bin to PATH
echo -- Adding %SystemRoot%\System32 to PATH
echo -- QMAKESPEC set to win32-g++
set QTDIR=D:\Qt\2010.05\qt
set PATH=D:\Qt\2010.05\qt\bin
set PATH=%PATH%;D:\Qt\2010.05\bin;D:\Qt\2010.05\mingw\ bin
set PATH=%PATH%;%SystemRoot%\System32
set PATH=%PATH%;D:\PostgreSQL\bin;D:\PostgreSQL\lib;D: \PostgreSQL\include
set QMAKESPEC=win32-g+

And i set the same in
Users environnement PATH variable,
System PATH environnemnet variable.

I would be very glad to anyone of you, who will be able to help me as i have been working on that for 3 days now, searching on various topics.
Best regards
Thanks!

Cyril.

My configuration is: Windows XP SP3, PostgreSQL 9.1 and Qt4.7 QtSDK 2010.05

ChrisW67
28th May 2012, 01:18
See the wiki article directly related to the Qt SDK: Building the Database Plugins for QtSDK Users.

The entire process on my machine:

Download and install PostgreSQL using the one click Windows installer (http://www.postgresql.org/download/windows/). I installed under "D:\PostgreSQL" giving me "D:\PostgreSQL\9.1\bin" etc.
Change directory to the psql sql driver source directory and build:

cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql
qmake INCLUDEPATH+="d:/PostgreSQL/9.1/include" LIBS+="d:/PostgreSQL/9.1/lib/libpq.lib"
mingw32-make
mingw32-make install
Compile and test your program in debug mode. The "D:\PostgreSQL\9.1\bin" directory needs to be in the user's PATH in order to use the plugin. The "...\lib" and "...\include" directories do not. I did that for testing purposes using the program run settings in Qt Creator.


The default steps only installed the debug model plugin. You will also want the Release mode plugin:


qmake INCLUDEPATH+="d:\PostgreSQL\9.1\include" LIBS+="d:\PostgreSQL\9.1\lib\libpq.lib" CONFIG+=release
mingw32-make
mingw32-make install

CyrilQt
28th May 2012, 16:41
Dear ChrisW67,

I downloaded and install Qt SDK from:
http://qt.nokia.com/downloads/sdk-windows-cpp-offline
in the D:\QtSDK directory
The path variable environnement checked with "Qt 4.8.1 Desktop (MinGW)" is set as followed


PATH=D:\QtSDK\mingw\bin;D:\QtSDK\Desktop\Qt\4.8.1\ mingw\bin;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;
D:\PostgreSQL\include;D:\PostgreSQL\lib;D:\Postgre SQL\bin;

As declare in Path i have the postgresql like this: D:\PostgreSQL

so i ran:


D:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql>qmake INCLUDEPATH +="D:/Pos
tgreSQL/include" LIBS+="D:/PostgreSQL/lib/libpq.lib"

but showed:
cannot find file INCLUDEPAHT
so i shifted to


D:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql>qmake "INCLUDEPATH +=D:/Pos
tgreSQL/include" "LIBS+=D:/PostgreSQL/lib/libpq.lib"

then OK.
then ran:
mingw32-make
console displays:


Creating library file:debug\libqsqlpsqld4.a
mingw32-make[1]: leaving directory'D:\QtSDK\QtSources\4.8.1\src\plugins
\sqldrivers\psql'

that looks good.
then i proceeded:


D:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql>mingw32-make install
mingw32-make -f Makefile.Debug install
mingw32-make[1]: Entering directory `D:/QtSDK/QtSources/4.8.1/src/plugins/sqldri
vers/psql'
copy /y "debug\qsqlpsqld4.dll" "d:\QtSDK\Desktop\Qt\4.8.1\mingw\plugins\sqldrive
rs\qsqlpsqld4.dll"
1 fichier(s) copié(s).
mingw32-make[1]: Leaving directory `D:/QtSDK/QtSources/4.8.1/src/plugins/sqldriv
ers/psql'

D:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql>


I opened my testing code:


#include<QApplication>
#include<QtSql/QSqlDatabase>
#include<QDebug>
#include<QtGui>

int main(int argc, char *argv[])
{

QApplication a(argc, argv);
QSqlDatabase bd = QSqlDatabase::addDatabase("QPSQL");
qDebug() << QSqlDatabase::drivers();
return a.exec();
}

and it answered me:


Démarrage de E:\cyril\Mes documents\Projets_Qt\test_connect_postgres1-build-desktop\debug\test_connect_postgres1.exe...("QSQLITE", "QODBC3", "QODBC", "QPSQL7", "QPSQL")

THANK YOU SO MUCH for helping me!!!

Best regards,
eternal gratitude.

Cyril.

ChrisW67
28th May 2012, 22:56
The error message regarding INCLUDEPATH is because you inckluded a space between the INCLUDEPATH and the "+=..." so Windows was treating it as two arguments, which in turn lead qmake to look for a file called INCLUDEPATH.


D:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql>qmake INCLUDEPATH +=D:/PostgreSQL/include LIBS+=D:/PostgreSQL/lib/libpq.lib
// ^^^ Here

Your quotes forced Windows to treat it as one argument and pass it to qmake as one argument. You could have left the space out, as in my example and the wiki page, with the same effect.

TerraxQt
28th November 2013, 16:33
See the wiki article directly related to the Qt SDK: Building the Database Plugins for QtSDK Users.

The entire process on my machine:

Download and install PostgreSQL using the one click Windows installer (http://www.postgresql.org/download/windows/). I installed under "D:\PostgreSQL" giving me "D:\PostgreSQL\9.1\bin" etc.
Change directory to the psql sql driver source directory and build:

cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\ps ql
qmake INCLUDEPATH+="d:/PostgreSQL/9.1/include" LIBS+="d:/PostgreSQL/9.1/lib/libpq.lib"
mingw32-make
mingw32-make install
Compile and test your program in debug mode. The "D:\PostgreSQL\9.1\bin" directory needs to be in the user's PATH in order to use the plugin. The "...\lib" and "...\include" directories do not. I did that for testing purposes using the program run settings in Qt Creator.


The default steps only installed the debug model plugin. You will also want the Release mode plugin:


qmake INCLUDEPATH+="d:\PostgreSQL\9.1\include" LIBS+="d:\PostgreSQL\9.1\lib\libpq.lib" CONFIG+=release
mingw32-make
mingw32-make install


Hello ChrisW67,

I am having troubles with Qt 5.1.1 when I try to build the plugin.

What I did:
- Added the directory C:\Program Files\PostgreSQL\9.3\bin with the C:\>set path=%path%;C:\Program Files\PostgreSQL\9.3\bin command.
- Tried C:\Qt\5.1.1\Src\qtbase\src\plugins\sqldrivers\psql>qmake INCLUDEPATH+="C:/Program Files/PostgreSQL/9.3/include" LIBS+="C:/Program Files/PostgreSQL/9.3/lib/libpq.lib" but I got the error below:
'qmake' is not recognized as an internal or external command, operable program or batch file.
- Searched where qmake is located and tried to execute the command above from there:

C:\Qt\5.1.1\mingw48_32\bin>qmake -makefile INCLUDEPATH+="C:/Program Files/PostgreSQL/9.3/include" LIBS+="C:/Program Files/PostgreSQL/9.3/lib/libpq.lib"

but instead I got answer how to use qmake:

Usage: qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project

Mode:
-project Put qmake into project file generation mode
In this mode qmake interprets files as files to
be built,
defaults to *; *; *; *.ts; *.xlf; *.qrc
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directory
<output omitted>

-Also tried to include the -makefile but the result is again how to use.

Could you please review this and advise?

Thanks in advance for your cooperation.

Best regards,
TerraxQt