QPSQL driver not loaded even though QPSQL driver is available



  • I am using Qt 4.8.2 to build a desktop app on linux that connects to a PostgreSQL database running in the background. I have build and installed the QPSQL driver. When I try to establish a connection to the database , I get the "Driver Not Loaded, Driver Not Loaded " error , even though QSqlDatabase reports that "QPSQL" is available. Here is my code :

    @ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("demo");
    db.setUserName("root");
    db.setPassword("ET_DIAGDB_CONTROL");
    db.setPort(5432);

    @

    on running the code , I get the following error:

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL QODBC3 QODBC QPSQL7 QPSQL

    I have checked that libqslqpsql.so is present in my plugins/sqldrivers directory and i have included the path to that directory in my paths



  • in the executable's path make sure you have the following files (I suppose you're using windows):

    comerr32.dll
    gssapi32.dll
    k5sprt32.dll
    krb5_32.dll
    libgcc_s_dw2-1.dll
    libiconv-2.dll
    libintl-8.dll
    libpq.dll
    mingwm10.dll
    msvcr71.dll

    you may also need:

    libssl32.dll
    libeay32.dll
    ssleay32.dll

    HTH



  • I am on linux



  • libpq.so.5 is (yum install PostgreSQL-libs) necessary for g++ to link the executable (Remember that in a Linux environment shared libraries have the extension .so not .dll).

    In the other hand, may be, there are some lines that you must add to your pro file (qMakefile):

    The variables accessible with this operator are typically used to enable third party plugins and components to be integrated with Qt. For example, a Qt Designer plugin can be installed alongside Qt Designer's built-in plugins if the following declaration is made in its project file:

    @
    target.path = $$[QT_INSTALL_PLUGINS]/designer
    INSTALLS += target
    @

    See in the documentation: qmake Advanced Usage

    good luck :)



  • in linux you should use ldd to find the dependencies of an executable/shared object

    for example:

    @
    $ ldd libqsqlpsql.so
    linux-gate.so.1 => (0xb77c4000)
    libpq.so.5 => /usr/lib/libpq.so.5 (0xb7770000)
    libQtSql.so.4 => /home/filippo/QtSDK/Desktop/Qt/4.8.1/gcc/lib/libQtSql.so.4 (0xb7730000)
    libQtCore.so.4 => /home/filippo/QtSDK/Desktop/Qt/4.8.1/gcc/lib/libQtCore.so.4 (0xb7448000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb7363000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7345000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb71a0000)
    ...

    @

    man ldd for further details.



  • Thanks! Idd told me that libpq.so.5 was missing. I included it in my LD_LIBRARY_PATH and it works now .



  • good


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.