Nominate our 2022 Qt Champions!

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;
        qDebug() << "opened!";
        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")

    How to build QPSQL driver ...i tried with many ways but failed ...can anybody help me with the steps..

  • Have you build Qt from source?
    Are you sure to have libpq5 and libpq-dev installed?

  • 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.

  • 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"
    $ make
    $ make install

    After that is done check that the library is located in $QTDIR/<version>/gcc_64/plugins/sqldrivers/

    That should be it.

  • 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..

  • @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

  • 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.

  • @mrdebug
    I always need to build the plugin myself.

    Do you install or build Qt yourself? Perhaps if you build it it detects that the pq libs are available and built the plugin automatically during the process.

  • 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.

Log in to reply