Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: QT to Postgresql connection

  1. #1
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QT to Postgresql connection

    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

  2. The following user says thank you to KeithN for this useful post:


  3. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    Have you built the Postgres (QPSQL) plugin for Qt? Does QPSQL appear in the output of QSqlDatabase::drivers()?

  4. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  5. #3
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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
    Last edited by KeithN; 7th November 2011 at 00:44.

  6. The following user says thank you to KeithN for this useful post:


  7. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    "nmake" is the Microsoft compiler suite make utility. If you are using the bundled MingW then substitute "mingw32-make".

  8. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  9. #5
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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

  10. The following user says thank you to KeithN for this useful post:


  11. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    The paths in this command:
    Qt Code:
    1. qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
    To copy to clipboard, switch view to plain text mode 
    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).

  12. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  13. #7
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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\\pl ugins\\sqldrivers\\psql\\include" "LIBS+=C:\\Program Files\\PostgreSQL\\9.1\\lib\\ms\\libpq.lib" psql.pro

    Regards, Keith

  14. The following user says thank you to KeithN for this useful post:


  15. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    Your INCLUDEPATH is still wrong.
    Qt Code:
    1. qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
    2. # The Postgres includes ^^^^^ and libraries ^^^^^^^
    To copy to clipboard, switch view to plain text mode 
    Notice that this points to the includes that come with Postgres and not anything to do with Qt as you are doing now.

    Try
    Qt Code:
    1. qmake -o Makefile "INCLUDEPATH+=C:\Program Files\PostgreSQL\9.1\include" "LIBS+=C:\Program Files\PostgreSQL\9.1\lib\ms\libpq.lib" psql.pro
    To copy to clipboard, switch view to plain text mode 

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

  16. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  17. #9
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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?

  18. The following user says thank you to KeithN for this useful post:


  19. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    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.

  20. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  21. #11
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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.

  22. The following user says thank you to KeithN for this useful post:


  23. #12
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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

  24. The following user says thank you to KeithN for this useful post:


  25. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    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...

  26. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  27. #14
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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

  28. The following user says thank you to KeithN for this useful post:


  29. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT to Postgresql connection

    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.

  30. The following 2 users say thank you to ChrisW67 for this useful post:

    KeithN (9th November 2011)

  31. #16
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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\mingw\bin;C:\WINDOWS\system32 ;C:\WINDOWS;C:\WINDOWS\System32\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.
    Last edited by KeithN; 9th November 2011 at 03:12.

  32. The following user says thank you to KeithN for this useful post:


  33. #17
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Firebird,Mysql and Postgres Drivers Ready To Download

    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/
    Attached Files Attached Files
    Last edited by thefatladysingsopera; 9th November 2011 at 12:38.

  34. The following 3 users say thank you to thefatladysingsopera for this useful post:

    KeithN (9th November 2011), rivci (4th May 2012)

  35. #18
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Firebird,Mysql and Postgres Drivers Ready To Download

    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

  36. The following user says thank you to KeithN for this useful post:


  37. #19
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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/1249...t-loaded-error

  38. The following 2 users say thank you to thefatladysingsopera for this useful post:

    KeithN (9th November 2011)

  39. #20
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    9
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT to Postgresql connection

    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

  40. The following user says thank you to KeithN for this useful post:


Similar Threads

  1. Replies: 2
    Last Post: 11th February 2011, 17:53
  2. Replies: 1
    Last Post: 2nd April 2010, 06:42
  3. requiredStatus on Qt 4.3 and PostgreSQL 8.3.3
    By Auryn in forum Qt Programming
    Replies: 9
    Last Post: 2nd September 2008, 22:06
  4. postgreSQL - Last Inserted ID
    By nnidza in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2007, 08:09
  5. QT4 and Postgresql driver
    By alphaqt in forum Installation and Deployment
    Replies: 6
    Last Post: 27th February 2006, 15:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.