PDA

View Full Version : How to load PSQL Driver for QT in Ubuntu



Srinivas_30sep
1st April 2011, 11:15
Hi ,

Please help me in loading the psql driver for QT in my Ubuntu 8.04.1 system.
Here Postgres 8.3.5 is also installed.


I had installed the QT using following commands

configure -static -nomake demos -nomake examples -nomake tools -qt-sql-psql

( As it is static , i guess no plugin option is needed )

make
sudo make install

Installation is done.

libqsqlpsql.a is created at the path /usr/local/Troll tech/Qt-4.5.1/plugins/sqldrivers

I had added the path to LIBS in makefile
i.e LIBS = -L/usr/local/Trolltech/Qt-4.5.1/plugins/sqldrivers

I had written the following code
#include<QtSql/QtSql>
#include <QtSql/QSqlDatabase>

qDebug() << "Sql Driver" << QSqlDatabase::drivers();
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("template1");
db.setUserName("postgres");
qDebug() << db.lastError();


After execution , i am getting the below error.


Sql Driver ()
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers:
QSqlError(-1, "Driver not loaded", "Driver not loaded")


It means Still Driver is not loaded.

Please mention what is missing or wrong here..

EAGERLY AWAITING THE RESPONSE.

Rhayader
1st April 2011, 11:45
From Qt docs "If you build the static version of Qt, static plugins is the only option for including Qt's predefined plugins." see the details in
http://doc.qt.nokia.com/4.7/plugins-howto.html#static-plugins

Srinivas_30sep
8th April 2011, 14:30
Hi Rhayader,

Thanks for suggesting the doc . As per the doc i included the following lines in the source file
#include <QtSql/QSqlDriverPlugin>
#include<QtCore/QtPlugin>
#define QT_STATICPLUGIN 1
Q_IMPORT_PLUGIN(qsqlpsql)

I am not using QMAKe and .pro file , instead i am using make file .
So i added
LIBS += -L/$QTDIR/plugins/sqldrivers/ -lqsqlpsql
I had also added
QT += sql
QTPLUGIN += qsqlpsql

in the Makefile.

Then when i compile i am getting below error
/opt/DEVROOT//obj/home/srinivasareddy.b/SqlWorks/DBForm/main.o: In function `StaticqsqlpsqlPluginInstance':
/home/srinivasareddy.b/SqlWorks/DBForm/myDBForm.h:9: undefined reference to `qt_plugin_instance_qsqlpsql()'
collect2: ld returned 1 exit status
make: *** [/opt/DEVROOT//bin/prd] Error 1

Please suggest , if anymore changes are needed.
I hope u moved me near to the solution .

AWAITING YOUR RESPONSE.