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

Thread: Access to PostgreSQL DB on a linux server

  1. #1
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Access to PostgreSQL DB on a linux server

    Hi All,

    My application is trying to connect to a PostgreSQL DB which has been created on a linux server (red hat 4)

    I am using the 4.3.3 version of Qt that I installed on my Home path.

    Follows the essential code I was trying to use to get theconnection to the db.
    It is simply a main.cpp:
    Qt Code:
    1. #include <QtCore>
    2. #include <QCoreApplication>
    3.  
    4. #include <QtSql>
    5.  
    6. //#include <QSqlDatabase>
    7. //#include <QSqlDriver>
    8. //#include <QSqlQuery>
    9.  
    10. #define DB_DRIVER "QPSQL"
    11. #define DB_HOST "127.0.0.1"
    12. #define DB_DBNAME "myDBname"
    13. #define DB_USER "myDBuser"
    14. #define DB_PASSWD "myDBpwd"
    15.  
    16.  
    17. int main(int argc, char *argv[])
    18. {
    19. QCoreApplication a(argc, argv);
    20.  
    21.  
    22. QSqlDatabase myDB = QSqlDatabase::addDatabase( DB_DRIVER );
    23.  
    24. myDB.setHostName( DB_HOST );
    25. myDB.setDatabaseName( DB_DBNAME );
    26. myDB.setUserName( DB_USER );
    27. myDB.setPassword( DB_PASSWD );
    28.  
    29. myDB.setConnectOptions("connect_timeout=15");
    30.  
    31. bool okDB = myDB.open();
    32.  
    33. if (!okDB) {
    34. printf("Error while trying to open the DB \n");
    35. //qWarning( "Error while trying to open the DB: "+ myDB.lastError().text() );
    36. return FALSE;
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    When I run the application..I always get the following:

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers:
    Error while trying to open the DB

    What should I do ?
    Can someone help me?

    Thank you very much..

    Roberto

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    J-P Nurmi

  3. #3
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    Thank you,

    I tried what you suggested but I get the same answer when I run the application..

    Is there another step to do?

    Could it be somthing like it is not finding the lib??

    Thank you

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Just to assure, you did the "make install" step too, right? What's the contents of /path/to/qt/plugins/sqldrivers?
    J-P Nurmi

  5. #5
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    No, I did not "make install", because on that machine I had not root privileges..
    anyway I did ./configure -prefix-install..

    Here is the list of files in that folder:

    libqsqlite.so
    libqsqlite.so.debug
    libqsqlmysql.so
    libqsqlmysql.so.debug
    libqsqlpsql.so
    libqsqlpsql.so.debug


    Thanks

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Hmm, what does
    qmake -query QT_INSTALL_PLUGINS
    output? Those plugins are in <output>/sqldrivers right? And what does
    ldd libqsqlpsql.so
    output?
    J-P Nurmi

  7. #7
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    IN: qmake -query QT_INSTALL_PLUGINS
    OUT:
    /usr/local/Trolltech/Qt-4.3.3/plugins

    mmhh strange ..that's not correct!!! it is a wrong path..



    IN: ldd libqsqlpsql.so
    OUT:
    libpq.so.4 => /usr/lib/libpq.so.4 (0x004f9000)
    libQtSql.so.4 => /home/fmas/qt-x11-opensource-src-4.3.3/lib/libQtSql.so.4 (0x00ad9000)
    libQtCore.so.4 => /home/fmas/qt-x11-opensource-src-4.3.3/lib/libQtCore.so.4 (0x00d1e000)
    libz.so.1 => /usr/lib/libz.so.1 (0x002c5000)
    librt.so.1 => /lib/tls/librt.so.1 (0x00381000)
    libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00323000)
    libdl.so.2 => /lib/libdl.so.2 (0x00f7c000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x008d2000)
    libm.so.6 => /lib/tls/libm.so.6 (0x00c09000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x003cf000)
    libc.so.6 => /lib/tls/libc.so.6 (0x00111000)
    libssl.so.4 => /lib/libssl.so.4 (0x0023c000)
    libcrypto.so.4 => /lib/libcrypto.so.4 (0x003d7000)
    libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00515000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x002d5000)
    libresolv.so.2 => /lib/libresolv.so.2 (0x00729000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x00813000)
    /lib/ld-linux.so.2 (0x005f9000)
    libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x00777000)
    libcom_err.so.2 => /lib/libcom_err.so.2 (0x00270000)
    libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00b6d000)

    How do you justify this??

    Thank you for your reply

  8. #8
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    The Path /usr/local/Trolltech/Qt-4.3.3/plugins

    does not exist..

    How do make sure It will be find the righ path?

  9. #9
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    Is there a way to set the QT_INSTALL_PLUGINS

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    This is all hardcoded to qmake by the time of configure. I guess something went wrong with configure.. At least the prefix seems to be not what you intended to.
    J-P Nurmi

  11. #11
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    Ok. I will try other solutions.

    Thanks a lot for you help anyway

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Oh, I almost forgot. You can always place the plugin into sqldrivers-subdir of the application binary.
    /path/to/app/binary
    /path/to/app/sqldrivers/libqsqlpsql.so
    J-P Nurmi

  13. #13
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to PostgreSQL DB on a linux server

    BINGO !!!

    It worked fine!!

    Thanks a lot ...you're great!

  14. #14
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Question Re: Access to PostgreSQL DB on a linux server

    Hi,

    I tried to run Robertos example but I can't find the libqsqlpsql files. I tried apt-cache search libsqlpsql with no result. My Qt-version is qt-4.3.3. In the path
    /usr/local/Trolltech/Qt-4.3.3/plugins/sqldrivers the only files is:
    libqsqlite.so libqsqlite.so.debug

    I also tried to search psql in synaptic and downloaded:
    postgresql-client
    postgresql-client-7.4
    postgresql-client-8.1
    libqt3-mt-psql

    I've got the libqsqlpsql.so but for qt3 so I still get the following errors when I'm running the program: (I tried to copy the libqsqlpsql.so for qt3 in the plugins/sqdrivers path for Qt4.33)

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE
    Error while trying to open the DB

    How can I find the libqslpsql files for qt4.3.3 ?
    Any help is deaply apreciated!

    gQt

  15. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Quote Originally Posted by gQt View Post
    How can I find the libqslpsql files for qt4.3.3 ?
    If Ubuntu repositories don't offer such package you might have to download Qt sources and compile it yourself.
    J-P Nurmi

  16. #16
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: Access to PostgreSQL DB on a linux server

    Thanks!

    It looks like I have to configure and make Qt again. I can't find the Qt source code for Unix/linux available for downloads. When I type ./configure -help after downloading an unpacking the tar.gz-file I get these options:

    { two posts merged and ./configure -help output removed }

    I guess I have to enable sql-pluggins and the psql-dev must be installed before ./configure, make. But I can't find any source/src option here? (My linux distribution is Debian) Any help is greatly apreciated!
    Regards
    gQt
    Last edited by jpn; 11th March 2008 at 11:52. Reason: removed ./configure -help output

  17. #17
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Quote Originally Posted by gQt View Post
    It looks like I have to configure and make Qt again. I can't find the Qt source code for Unix/linux available for downloads.
    ftp://ftp.trolltech.com/qt/source

    When I type ./configure -help after downloading an unpacking the tar.gz-file I get these options:
    Yes, anyone can run ./configure -help him/herself and get exactly the same output on X11.

    I guess I have to enable sql-pluggins and the psql-dev must be installed before ./configure, make. But I can't find any source/src option here?
    Yes, if you need SQL-plugins you either turn them on while building Qt by passing appropriate -sql-xxxxx options to configure OR you build the plugin manually after Qt has been built.
    J-P Nurmi

  18. #18
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: Access to PostgreSQL DB on a linux server

    Thanks for the links!

    If I understand I can go to the QtDir and type: make confclean, then run the ./configure script with the wright options for sql pluggins: -pluggin-sql-<driver>

    or build the QPSQL Plugin on Unix and Mac OS X manually
    (for psql)

    cd $QTDIR/src/plugins/sqldrivers/psql
    qmake -o Makefile "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
    make

    My Qt-installation lack the src-dir under QTDIR and I can't find out how to download just the source. the link: ftp://ftp.trolltech.com/qt/source refers only to full Qt-installations, or am I wrong?

    Is it a configure option to specify that the src-dir should be downloaded too ? I can't see that from the ./configure -options

  19. #19
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access to PostgreSQL DB on a linux server

    Well, you can't re-compile Qt if you installed a binary package from your distribution's repository (because you don't have the sources). So the option is to go grab a source package, for example qt-x11-opensource-src-4.3.4.tar.gz, and compile that by yourself.
    J-P Nurmi

  20. #20
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: Access to PostgreSQL DB on a linux server

    Thanks for replying!

    That's the strange thing, I downloaded the qt-x11-commercial-src-4.3.3.tar.gz and this file should also be a source package, but I could remove the installation and install the opensource version instead.

Similar Threads

  1. Replies: 0
    Last Post: 16th April 2007, 13:18
  2. Replies: 1
    Last Post: 4th October 2006, 17:05
  3. Access MS .mdb file on Linux
    By iGoo in forum Qt Programming
    Replies: 3
    Last Post: 15th June 2006, 10:42

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.