[PyQt] Database Connection
marion.balthasar at ise.fraunhofer.de
marion.balthasar at ise.fraunhofer.de
Fri May 4 21:20:50 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070504/fe491608/attachment-0001.html
More information about the PyQt
mailing list