PostgreSQL drivers build and use



  • I am trying to get a Qt connection to PostgreSQL. I have made a few changes to get things to work
    So I'll give the details so you know where I am and how I got there.

    Current Sys config:
    Windows 8 64-bit
    postgresql-9.2.4
    Qt 5.0.2 mingw 32- bit

    First I build the ..\5.0.2\Src\qtbase\src\plugins\sqldrivers\psql\psql.pro
    to point the psql.pro to my PostgreSQL I added the following to my psql.pro

    @
    INCLUDEPATH += $$quote("C:/pgsql/include/")
    @

    But when I did that I got
    .. \mingw\i686-w64-mingw32\include\sys\timeb.h:90: error: previous definition of 'struct timespec'

    Which is a conflict between the two following defines. One from Qt and another from PostgreSQL

    timeb.h
    @
    #ifndef _TIMESPEC_DEFINED
    #define _TIMESPEC_DEFINED
    struct timespec {
    time_t tv_sec; /* Seconds /
    long tv_nsec; /
    Nanoseconds */
    };
    @

    pgsql\include\pthread.h
    @
    #ifndef HAVE_STRUCT_TIMESPEC
    #define HAVE_STRUCT_TIMESPEC 1
    struct timespec {
    long tv_sec;
    long tv_nsec;
    };
    #endif /* HAVE_STRUCT_TIMESPEC */
    @

    To fix this I added this to my psql.pro
    @
    DEFINES += HAVE_STRUCT_TIMESPEC
    @

    This build but for some strange reason put the files in a new folder C:\plugins\sqldrivers
    libqsqlpsql.a
    libqsqlpsqld.a
    qsqlpsql.dll
    qsqlpsqld.dll

    I copied them to here
    ..\5.0.2\mingw47_32\plugins\sqldrivers\

    When I try and use this in QT now I am getting the following.
    The code

    @ qDebug() << "Available drivers: " << QSqlDatabase::drivers();
    *db = QSqlDatabase::addDatabase("QPSQL");
    qDebug() << "addDatabase() " << (db->isValid() ? "VALID" : "ERROR");
    db->setUserName("postgres");
    db->setPassword("postgres");
    db->setDatabaseName(DBName);
    db->open();
    @

    gives me the following errors:

    @Available drivers: ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    addDatabase() ERROR
    Available drivers: ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
    can't find linker symbol for virtual table for QSqlDriver' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QSqlDriver' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QSqlDriver' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QSqlDriver' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QSqlDriver' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QObjectData' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QObjectData' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    can't find linker symbol for virtual table for QObjectPrivate' value foundQSqlDatabasePrivate::shared_null()::dr' instead
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    Debugging has finished
    @

    Have I build the PostgreSQL drivers incorrectly?

    Do I need to do something other than place the drivers into the \plugins\sqldrivers\ dir?

    edit
    I have just tried putting QTPLUGIN += qsqlpsql into my test.pro file but it does not seem to have any affect.


Log in to reply
 

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