简体   繁体   中英

QT - PostgreSQL plugin error

I have an app, that should connect to database. Under linux i've no problems, but under windows - > i've to add to system "Path" place, where QT enviroment is placed (C:/QT/Tools/QTCreator/bin) otherwise it doesn't work and shows errors like below. id doesn't work if i place exe file on pendrive too

i would like to send this app to my firends, who shouldn't install QT environment and just run this app.

dirs on my pendrive

/ app.exe plugins (dir) -qsqlpsql.dll -sqldrivers (dir) --qsqlpsql.dll

what should i do? where did i mistake?

pro file:

QT       += core gui sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = NZP
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui
win32{
LIBS += -L"C:/Program Files/psqlODBC/0903/bin"
}
RC_FILE += Info.rc

in my main.cpp:

QApplication a(argc, argv);
   qDebug()<<QCoreApplication::applicationDirPath();
   a.addLibraryPath(QCoreApplication::applicationDirPath());
   a.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins");
   qDebug()<<a.libraryPaths();

    MainWindow w;
    w.show();

    return a.exec(); 

if i run this app under windows, where i installed QT - everythink is correct, but if i move it on pendrive or run under machine without QT framework - i become error:

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

Failed to open database connection. Invalid driver specfied.

i have looked in internet, but by now without sensible solution help!

Ugh! i found the problem!

1. you have in your install destination this folder structure:

yourap.exe
-plugins -> folder
--sqldrivers -> folder
and you have to copy from migws/bin  not QT/Tools/Creator/bin! 
---qsqlpsql.dll

in your app directory you have to copy

libeay32.dll

with you found in:

C:\Program Files\psqlODBC\0903\bin (http://www.postgresql.org/ftp/odbc/versions/msi/   - ii used https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_03_0300.zip)

in your app (main.cpp), just add path:

QApplication a(argc, argv);
a.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins/");
a.addLibraryPath(QCoreApplication::applicationDirPath());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM