Important: Please read the Qt Code of Conduct -

[SOLVED] PostgreSQL linker error

  • Hi! I compile PostgreSQL with "this": instruction, build without problem, then try use this driver, when i write this code:
    @ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    if (!
    ui.textEdit->append(QString("%1: "%2 %3"").arg(QDateTime::currentDateTime().toString("hh:MM:ss")).arg(QObject::tr("DB not found:")).arg(db.lastError().text()));

    i have result: 11:04:15: "DB not found: Driver not loaded Driver not loaded"

    when i try use this code (found them at the assistent):
    @#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"

    PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
    QPSQLDriver *drv = new QPSQLDriver(con);
    QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
    QSqlQuery query;
    query.exec("SELECT NAME, ID FROM STAFF");@

    i have trouble with linker:

    test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const QPSQLDriver::`vftable'" (_imp??_7QPSQLDriver@@6B@) referenced in function "public: __thiscall QPSQLDriver::QPSQLDriver(class QObject *)" (??0QPSQLDriver@@QAE@PAVQObject@@@Z)

    1>test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QPSQLDriver::tr(char const *,char const *)" (_imp?tr@QPSQLDriver@@SA?AVQString@@PBD0@Z) referenced in function "public: virtual bool __thiscall QPSQLDriver::open(class QString const &,class QString const &,class QString const &,class QString const &,int,class QString const &)" (?open@QPSQLDriver@@UAE_NABVQString@@000H0@Z)

    1>test.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QPSQLDriver::metaObject(void)const " (?metaObject@QPSQLDriver@@UBEPBUQMetaObject@@XZ)

    1>test.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QPSQLDriver::qt_metacast(char const *)" (?qt_metacast@QPSQLDriver@@UAEPAXPBD@Z)

    1>test.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QPSQLDriver::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QPSQLDriver@@UAEHW4Call@QMetaObject@@HPAPAX@Z)

    some one know, what lib's i need link to my project for resolve this issue or how to correct register driver?

    ps: i add libpq.lib to current project

  • I think that the Qt-driver(plugin) for postgresql depends on dynamic library libpq.dll. It doesn't find it and gives out errors.

  • I try copy libqp.dll to plugin QtDir\plugins\sqldrivers this is not resolve an issue, then add to the PATH PostgreSQL lib folder this is not reslove my issue to :(

    any other ideas?

  • I use MinGW version of Qt. I copied libpq.dll file in BIN subdirectory of Qt distribution. It works for me.

  • i forget to write, i use visual studio and nmake for compiling, Qt installing from distributive for MSVC2008.

  • I add dependence to dll's which contains at the PostgreSQL/bin folder, and driver start work.

    tnx a lot All 4 help!

Log in to reply