Steps of how to build QPSQL driver on linux(ubuntu 14.04)?
-
Hi,
i'm newbie to Qt...i wanted to interface Qt with postgresql database.....i tried with this following code but failed to do that...Any help is appreciated..QSqlDatabase mydb; mydb.addDatabase("QPSQL"); mydb.setHostName("192.168.2.24"); mydb.setDatabaseName("conf"); mydb.setUserName("postgres"); mydb.setPassword("cdt321"); mydb.setPort(5432); mydb.setConnectOptions(); if(mydb.open()) { qDebug() << "opened!"; } else { qDebug() << mydb.lastError(); }
After Execution....
I'm left with the Error message as follows
Starting /run/user/0/gvfs/smb-share:server=main,share=data/Vijay/tableWidget/tableWidget...
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
QSqlError(-1, "Driver not loaded", "Driver not loaded")
("QSQLITE")How to build QPSQL driver ...i tried with many ways but failed ...can anybody help me with the steps..
-
The following steps should get you going, you need the Qt sources (if you use the online installer just run it and also download the sources for the Qt version that you have already installed)
PS: You do not need to build Qt from source, but you need the sources to build the plugin.
$ sudo apt-get install libpq-dev $ cd $QTDIR/<version>/Src/qtbase/src/plugins/sqldrivers/psql $ qmake "INCLUDEPATH+=/usr/include/postgresql" "LIBS+=-L/usr/lib -lpq" psql.pro $ make $ make install
After that is done check that the
libqsqlpsql.so
library is located in$QTDIR/<version>/gcc_64/plugins/sqldrivers/
That should be it.
-
@vIJI
You need to replace the $QTDIR with your actual path to Qt, so you end up with something like:/opt/Qt/5.4/Src/qtbase/src/plugins/sqldrivers/psql
Also I am pretty sure that you should not have version 3.0.1 of Qt, that might be your version of QtCreator (not the same).
Make sure where Qt was installed and what version of Qt you have.
Perhaps run the following to see what version is installed:
qmake --version