Steps of how to build QPSQL driver on linux(ubuntu 14.04)?
-
wrote on 2 Dec 2015, 11:40 last edited by
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..
-
wrote on 2 Dec 2015, 12:58 last edited by
Have you build Qt from source?
Are you sure to have libpq5 and libpq-dev installed? -
wrote on 3 Dec 2015, 04:07 last edited by
Yes, i do have libpq and libpd-dev files......and whats Qt installed from source?
Will you please brief about that?Thank you for the reply.
-
wrote on 3 Dec 2015, 05:45 last edited by TheBadger 12 Mar 2015, 05:47
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.
-
wrote on 3 Dec 2015, 06:10 last edited by
After running cd $QTDIR/3.0.1/Src/qtbase/src/plugins/sqldrivers/psql
its showing no such file or directory....and i think in dont have qtbase file..
-
After running cd $QTDIR/3.0.1/Src/qtbase/src/plugins/sqldrivers/psql
its showing no such file or directory....and i think in dont have qtbase file..
wrote on 3 Dec 2015, 06:33 last edited by@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
-
wrote on 3 Dec 2015, 07:41 last edited by
This situation is a little bit strange.
I normally use PostgreSql with Qt (WIndows, Linux, Mac) without any problem.
In the Linux machine I only need the libpq5 and libpq-dev, and the Qt plugins directory. -
This situation is a little bit strange.
I normally use PostgreSql with Qt (WIndows, Linux, Mac) without any problem.
In the Linux machine I only need the libpq5 and libpq-dev, and the Qt plugins directory. -
wrote on 3 Dec 2015, 09:06 last edited by
Only in arm, in i386 I use the Qt official pachage.
Maybe the problem is the qt.conf file. Maybe the plugins directory is not in the correct position.
1/9