[PyQt] Database Connection still does not work...

daloonia at gmx.de daloonia at gmx.de
Sun May 6 18:44:34 BST 2007


On 04.05.07 20:22:47, marion.balthasar at ise.fraunhofer.de wrote:
> >from PyQt4.QtSql import *
> >from PyQt4.QtCore import *
> 
> class Database:
> 
>     def __init__(self):
> 
>         self.db=QSqlDatabase.addDatabase("QPSQL")
>         self.db.setHostName("localhost")
>         self.db.setDatabaseName("klimadaten")
>         self.db.setUserName("postgres")
>         self.db.setPassword("post")
> 
>         self.db.open()
>         self.db.QSqlDatabase.lastError().text()
> 
> 
> 
> But when i start "run module" in IDLE there is no message at all, no 
> error-message, nothing...
> 
> I think I missed to add parts in the source, but as i'm not really used 
to 
> python scripting, i can't figure out now, which one it may be,

This only declares a class, you need to create an instance of the class,
add something like

c=Database()

at the end of the script.

> >from PyQt4.QtSql import *
> QSqlDatabase.addDatabase("QPSQL")
> 
> in Python Interpreter, then the error-message "QSqlDatabase: driver not 
> loaded
> QSqlDatabase: 
> available drivers 
>  PyQt4.QtSql.QSqlDatabase object at 0x008E58A0"

That means your PyQt doesn't have the qt psql plugin, did you install Qt
yourself or did you use a distro package? If the former then make sure
your Qt was built with the postgres plugin, its in
<qt-install-dir>/plugins/sqldrivers and called libqsqlpsql.so.

> Maybe I have to make some more specific determinations to the driver?

No, but the driver also needs to find its dependecies, i.e. it needs to
find the postgresql client library. Run ldd libqsqlpsql.so to see wether
any libs are missing.

Andreas

Andreas, Matt, thanks a lot for your replies!!

I finally figured out (due to your hints), that i didn't had the driver 
built. So i'm now running a new built of Qt including psql :-)
when i first installed qt, i used the precompiled binary package for 
windows.. but now I've explicitely mentioned in configuration to built 
psql!!
Although i know, that this probably means, that i have to reinstall sip 
and pyqt as well... (am i right?)

last but not least, i really have to improve, or better practise 
programming... ;-) i will also post the upcoming problems here ;-))

have a nice evening!

marion


Hi again,

I finally managed to successfully build Qt with makefiles and have now libqsqlpsql.dll in plugin directory. I have also set environmentvariables (as I don't have admin rights on my PC here at work, I always run this batch file in cmd shell:

set Path=C:\Bin;C:\Bat;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;
C:\python25;C:\Qt\4.2.3\bin;C:\PyQt4.2\;C:\Programme\qgistrunk;C:\mingw\bin;
C:\Programme\PostgreSQL\8.2;C:\cmake\bin;C:\mingw\include;C:\Programme\PostgreSQL\8.2
set PGLIB=C:\Programme\PostgreSQL\8.2\lib
set PGINCLUDE=C:\Programme\PostgreSQL\8.2\include
set PGBIN=C:\Programme\PostgreSQL\8.2\bin
set PGDATA=C:\Programme\PostgreSQL\8.2\data
set PGUSER=postgres
set QT_DEBUG_PLUGINS=1

when I then run Python from shell and just want to test if it's possible to  creat a connection, the same errormessage occured...:
> >from PyQt4.QtSql import *
> QSqlDatabase.addDatabase("QPSQL")
> 
> in Python Interpreter, then the error-message "QSqlDatabase: driver not 
> loaded
> QSqlDatabase: 
> available drivers 
>  PyQt4.QtSql.QSqlDatabase object at 0x008E58A0"

So, I really don't know what goes wrong with this...

Would be so great, if anyone can help me to step forward with this stuff :-)

Thanks in advance,
Marion.
-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


More information about the PyQt mailing list