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:
Code:
#include <QtCore>
#include <QCoreApplication>
#include <QtSql>
//#include <QSqlDatabase>
//#include <QSqlDriver>
//#include <QSqlQuery>
#define DB_DRIVER "QPSQL"
#define DB_HOST "127.0.0.1"
#define DB_DBNAME "myDBname"
#define DB_USER "myDBuser"
#define DB_PASSWD "myDBpwd"
int main(int argc, char *argv[])
{
myDB.setHostName( DB_HOST );
myDB.setDatabaseName( DB_DBNAME );
myDB.setUserName( DB_USER );
myDB.setPassword( DB_PASSWD );
myDB.setConnectOptions("connect_timeout=15");
bool okDB = myDB.open();
if (!okDB) {
printf("Error while trying to open the DB \n");
//qWarning( "Error while trying to open the DB: "+ myDB.lastError().text() );
return FALSE;
}
}
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
Re: Access to PostgreSQL DB on a linux server
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
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?
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
Re: Access to PostgreSQL DB on a linux server
Hmm, what does
Quote:
qmake -query QT_INSTALL_PLUGINS
output? Those plugins are in <output>/sqldrivers right? And what does
Quote:
ldd libqsqlpsql.so
output?
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
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?
Re: Access to PostgreSQL DB on a linux server
Is there a way to set the QT_INSTALL_PLUGINS
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.
Re: Access to PostgreSQL DB on a linux server
Ok. I will try other solutions.
Thanks a lot for you help anyway
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.
Quote:
/path/to/app/binary
/path/to/app/sqldrivers/libqsqlpsql.so
Re: Access to PostgreSQL DB on a linux server
BINGO !!!
It worked fine!!
Thanks a lot ...you're great!
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
Re: Access to PostgreSQL DB on a linux server
Quote:
Originally Posted by
gQt
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.
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
Re: Access to PostgreSQL DB on a linux server
Quote:
Originally Posted by
gQt
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
Quote:
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.
Quote:
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.
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
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.
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.