PDA

View Full Version : use qpsql



raphaelf
5th July 2006, 08:24
Hi everybody,
QT: 4.1.3
OS: WIN XP

I tried to connect to my sql server via odbc and it works perfect. I have installed postgre 8.1 on my machine and build the plugin for postgre. I get a new file "qsqlpsql.dll". So i would like to connect it to a Postgre database. I get the known error: Driver not loaded, driver not loaded.
Here my code:


QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("inventar");
db.setUserName("postgres");
db.setPassword("tekoteko");
if(!db.open())
{
QMessageBox::information(this,"",db.lastError().text());
return false;
}
else
{
. . .



What could i try to make my connection running?

Thanks :crying:

wysota
5th July 2006, 08:55
Check the dependencies of the driver using dependency walker. Maybe the plugin can't find some library it needs.

raphaelf
5th July 2006, 10:58
Hi wysota!!
I downloaded dependency walker and check qsqlpsql.dll
I get a yellow question mark for "LIBPQ.dll", what should i do now? :o

jacek
5th July 2006, 12:23
I get a yellow question mark for "LIBPQ.dll", what should i do now? :o
Find it and copy to the same directory where the executable is.

raphaelf
5th July 2006, 12:29
Hi Jacek,
I copyed the dll to the directory and i get the same error "driver not loaded" :crying:

jacek
5th July 2006, 12:47
I copyed the dll to the directory and i get the same error "driver not loaded" :crying:
AFAIR you need more than one DLL. Check what DLLs libpq.dll requires.

raphaelf
5th July 2006, 13:31
Hi Jacek,
I copied all dlls from postgres and i get the same error :crying:
With QT3.2.1 i can remenber that i had no problem to connect me to my postgre database.
Do QT4 support Postgre 8.1?
What could i try now?? :confused:

jacek
5th July 2006, 13:46
Do QT4 support Postgre 8.1?
Of course it does. Which Qt version do you have exactly?

raphaelf
5th July 2006, 13:57
Hi!!
QT4.1.3 Open Source Edition
MINGW 4.1 :crying:

jacek
5th July 2006, 17:19
QT4.1.3 Open Source Edition
I had no problems with this version. To be able to load the plugin, I had to add libeay32.dll, libpq.dll and libssl32.dll

raphaelf
25th July 2006, 12:47
Hi everybody :crying:
I add these dlls to my path: libeay32.dll, libpq.dll and qsqlpsql.dll
I could not find libssl32.dll on my system.
but i am not able to connect to my postgre databse. What could i try to solve my problem?



QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("inventarMp");
db.setUserName("postgres");
db.setPassword("");
if(!db.open())
{
QMessageBox::information(this,"",db.lastError().text());
return false;
}
else
{..

ERROR: Driver not loaded :crying:

raphaelf
3rd August 2006, 07:41
hi everybody,
can somebody see why i am not able to connect me to a postgre database :confused:

thanks

jacek
3rd August 2006, 13:03
Where did you place the plugin and PostgreSQL DLLs?

raphaelf
3rd August 2006, 13:33
hi jacek,
i add libeay32.dll, libpq.dll and qsqlpsql.dll there where my .exe file is (in the release folder) :o

have you a idea?

jacek
3rd August 2006, 13:41
Then move qsqlpsql.dll to the sqldrivers subdirectory.

raphaelf
7th August 2006, 08:33
hi jacek,
this dll is allready under: D:\apps\Qt\4.1.3\plugins\sqldrivers
:o

jacek
7th August 2006, 11:45
this dll is allready under: D:\apps\Qt\4.1.3\plugins\sqldrivers
Then copy it to the sqldrivers subdirectory of the directory where your executable is.

raphaelf
17th August 2006, 07:45
Hi Jacek,
I create the sqldrivers directory, copy this dlls: libeay32.dll, libpq.dll, qsqlpsql.dll
I get the same error message: DRIVER NOT LOAD DRIVER NOT LOAD :crying:
Mission Impossible..:confused:

jacek
17th August 2006, 12:16
I create the sqldrivers directory, copy this dlls: libeay32.dll, libpq.dll, qsqlpsql.dll
Only qsqlpsql.dll should go the sqldrivers, the rest should remain in the same directory where your executable is.

Did you compile the plugin and Qt with the same compiler and same build key?

raphaelf
17th August 2006, 12:33
Hi!
I put just qsqlpsql.dll now in my sqldrivers directory.
Yes i have compiled QT and Plugin with the same Compiler.

What is a build key?

jacek
17th August 2006, 12:43
What is a build key?
It's a special string that you can assign to your Qt DLLs and plugins. When Qt loads a plugin it checks whether both keys are the same, but since you have never heard about it, you have probably probably left the default values, so it shouldn't be a problem.

Open libeay32.dll and libpq.dll in Dependency Walker (http://www.dependencywalker.com) and see if there are some DLLs missing. If it finds some, post them here.

raphaelf
17th August 2006, 13:56
Hi,
libeay32.dll seems to miss nothing
libpq.dll seems to miss (i get a yellow question mark):
- COMERR32.DLL
- LIBINTL-2.DLL
- KRB5_32.DLL
- SSLEAY32.DLL

If i open LIBPQ.DLL from the original path: D:\apps\PostgreSQL\8.1\bin then its missing nothing..

jacek
17th August 2006, 15:17
If i open LIBPQ.DLL from the original path: D:\apps\PostgreSQL\8.1\bin then its missing nothing..
Then copy all missing DLLs from D:\apps\PostgreSQL\8.1\bin to the directory where your executable is.

ball
19th August 2006, 02:53
Just put those DLL into c:\windows\system32\

jacek
19th August 2006, 13:30
Just put those DLL into c:\windows\system32\
This is a bit dangerous solution. What if there is another program that uses those DLLs, but for example their older versions?

ball
20th August 2006, 12:37
Yeah you are right but in this case, we need to make his program get running as first priority problem to be solved.

raphaelf
21st August 2006, 14:01
Hi everybody :crying:
I put the dlls where my .exe is and i get the same error: driver not loaded..
I really dont know what to do now :confused:

P.S. If i start the sql browser example, i can just see: qsqlite and qodbc, but no qsqlpsql. Did this information help??

Please help me to solve my problem..With QT3.2.1 i could connect me without problem to a postgre database..

jacek
21st August 2006, 14:20
I put the dlls where my .exe is and i get the same error: driver not loaded..
Check all DLLs you have copied with Dependency Walker(you might be missing libiconv-2.dll).

The other solution is to recompile Qt with -qt-sql-psql option, so that the driver will be compiled into the library. This way when you start your application it should tell you what DLLs are missing.

raphaelf
21st August 2006, 14:28
Hi Jacek,
I think its a good idea..
Should i type this comand to configure it:
configure -qt-sql-psql
make

Or should i deinstall QT and install it again?

jacek
21st August 2006, 14:42
Should i type this comand to configure it:
configure -qt-sql-psql
And then "make", but it will take few hours. Make a copy of your current Qt directory, so that you won't have to recompile it again.

Checking with Dependency Walker will take at most few minutes.

raphaelf
21st August 2006, 15:01
Hi Jacek,
I get following Error by configuring QT:



o tmp\obj\debug_shared\qsql_psql.o drivers\psql\qsql_psql.cpp
drivers\psql\qsql_psql.cpp:37:22: libpq-fe.h: No such file or directory
drivers\psql\qsql_psql.cpp: In function `QSqlError qMakeError(const QString&, QS
qlError::ErrorType, const QPSQLDriverPrivate*)':
drivers\psql\qsql_psql.cpp:122: error: `PQerrorMessage' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:122: error: (Each undeclared identifier is reported o
nly once for each function it appears in.)
drivers\psql\qsql_psql.cpp: In member function `bool QPSQLResultPrivate::process
Results()':
drivers\psql\qsql_psql.cpp:132: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:133: error: `PGRES_TUPLES_OK' undeclared (first use t
his function)
drivers\psql\qsql_psql.cpp:136: error: `PQntuples' undeclared (first use this fu
nction)
drivers\psql\qsql_psql.cpp:138: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp: In member function `void QPSQLResult::cleanup()':
drivers\psql\qsql_psql.cpp:216: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLResult::fetchL
ast()':
drivers\psql\qsql_psql.cpp:244: error: `PQntuples' undeclared (first use this fu
nction)
drivers\psql\qsql_psql.cpp: In member function `virtual QVariant QPSQLResult::da
ta(int)':
drivers\psql\qsql_psql.cpp:249: error: `PQnfields' undeclared (first use this fu
nction)
drivers\psql\qsql_psql.cpp:253: error: `PQftype' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp:255: error: `PQgetvalue' undeclared (first use this f
unction)
drivers\psql\qsql_psql.cpp:256: error: `PQgetisnull' undeclared (first use this
function)
drivers\psql\qsql_psql.cpp:306: error: `PQunescapeBytea' undeclared (first use t
his function)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLResult::isNull
(int)':
drivers\psql\qsql_psql.cpp:320: error: `PQgetvalue' undeclared (first use this f
unction)
drivers\psql\qsql_psql.cpp:321: error: `PQgetisnull' undeclared (first use this
function)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLResult::reset(
const QString&)':
drivers\psql\qsql_psql.cpp:333: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp: In member function `virtual int QPSQLResult::numRows
Affected()':
drivers\psql\qsql_psql.cpp:344: error: `PQcmdTuples' undeclared (first use this
function)
drivers\psql\qsql_psql.cpp: In member function `virtual QVariant QPSQLResult::la
stInsertId() const':
drivers\psql\qsql_psql.cpp:350: error: `Oid' undeclared (first use this function
)
drivers\psql\qsql_psql.cpp:350: error: expected `;' before "id"
drivers\psql\qsql_psql.cpp:351: error: `id' undeclared (first use this function)

drivers\psql\qsql_psql.cpp:351: error: `InvalidOid' undeclared (first use this f
unction)
drivers\psql\qsql_psql.cpp: In member function `virtual QSqlRecord QPSQLResult::
record() const':
drivers\psql\qsql_psql.cpp:363: error: `PQnfields' undeclared (first use this fu
nction)
drivers\psql\qsql_psql.cpp:367: error: `PQfname' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp:370: error: `PQftype' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp:371: error: `PQfsize' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp:372: error: `PQfmod' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp: In function `bool setEncodingUtf8(PGconn*)':
drivers\psql\qsql_psql.cpp:390: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:391: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:392: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp:393: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp: In function `void setDatestyle(PGconn*)':
drivers\psql\qsql_psql.cpp:398: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:399: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:400: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp:401: error: `PQerrorMessage' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:402: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In function `QPSQLDriver::Protocol getPSQLVersion(PG
conn*)':
drivers\psql\qsql_psql.cpp:407: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:408: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:409: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp:409: error: `PGRES_TUPLES_OK' undeclared (first use t
his function)
drivers\psql\qsql_psql.cpp:410: error: `PQgetvalue' undeclared (first use this f
unction)
drivers\psql\qsql_psql.cpp:411: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In destructor `virtual QPSQLDriver::~QPSQLDriver()':

drivers\psql\qsql_psql.cpp:464: error: `PQfinish' undeclared (first use this fun
ction)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLDriver::open(c
onst QString&, const QString&, const QString&, const QString&, int, const QStrin
g&)':
drivers\psql\qsql_psql.cpp:535: error: `PQconnectdb' undeclared (first use this
function)
drivers\psql\qsql_psql.cpp:536: error: `PQstatus' undeclared (first use this fun
ction)
drivers\psql\qsql_psql.cpp:536: error: `CONNECTION_BAD' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp: In member function `virtual void QPSQLDriver::close(
)':
drivers\psql\qsql_psql.cpp:555: error: `PQfinish' undeclared (first use this fun
ction)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLDriver::beginT
ransaction()':
drivers\psql\qsql_psql.cpp:573: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:574: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:574: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp:575: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLDriver::commit
Transaction()':
drivers\psql\qsql_psql.cpp:590: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:591: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:591: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp:592: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLDriver::rollba
ckTransaction()':
drivers\psql\qsql_psql.cpp:607: error: `PQexec' undeclared (first use this funct
ion)
drivers\psql\qsql_psql.cpp:608: error: `PQresultStatus' undeclared (first use th
is function)
drivers\psql\qsql_psql.cpp:608: error: `PGRES_COMMAND_OK' undeclared (first use
this function)
drivers\psql\qsql_psql.cpp:611: error: `PQclear' undeclared (first use this func
tion)
drivers\psql\qsql_psql.cpp: In member function `virtual QString QPSQLDriver::for
matValue(const QSqlField&, bool) const':
drivers\psql\qsql_psql.cpp:873: error: `PQescapeBytea' undeclared (first use thi
s function)
drivers\psql\qsql_psql.cpp: In member function `virtual bool QPSQLDriver::isOpen
() const':
drivers\psql\qsql_psql.cpp:903: error: `PQstatus' undeclared (first use this fun
ction)
drivers\psql\qsql_psql.cpp:903: error: `CONNECTION_OK' undeclared (first use thi
s function)
mingw32-make[3]: *** [tmp\obj\debug_shared\qsql_psql.o] Error 1
mingw32-make[3]: Leaving directory `D:/apps/Qt/4.1.3/src/sql'
mingw32-make[2]: *** [debug-all] Error 2
mingw32-make[2]: Leaving directory `D:/apps/Qt/4.1.3/src/sql'
mingw32-make[1]: *** [sub-sql-make_default-ordered] Error 2
mingw32-make[1]: Leaving directory `D:/apps/Qt/4.1.3/src'
mingw32-make: *** [sub-src-make_default-ordered] Error 2

jacek
21st August 2006, 16:10
drivers\psql\qsql_psql.cpp:37:22: libpq-fe.h: No such file or directory
Qt can't find PostgreSQL's headers. Pass -I and -L parameters with proper value to configure.

raphaelf
22nd August 2006, 12:11
Hi Jacek!! :p
It works after configure QT and set the Path and Lib with the Parameter -L and -I
And i had to copy some dlls..Qt say me which dlls was misssing..
Thanks

But i have a question: Why do i get my exe file under the debug folder and not under the release folder?And what is the diference?

jacek
22nd August 2006, 12:19
Why do i get my exe file under the debug folder and not under the release folder?And what is the diference?
Under windows, qmake creates two Makefiles: Makefile.Release and Makefile.Debug. The latter is the default one and it compiles application with debugging symbols. To compile your application in "release" mode (i.e. optimized and without debugging information), you must run "make -f Makefile.Release".

You can switch that feature off by adding:

CONFIG -= debug_and_release
CONFIG += release # or debugto your .pro file.

raphaelf
22nd August 2006, 12:52
Hi Jacek!!

Thanks for your spended time and very good support :rolleyes:
It works perfect :p