*** GMX Spamverdacht *** Antwort: Re: [PyQt] Database Connection
Andreas Pakulat
apaku at gmx.de
Fri May 4 20:28:58 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
--
Caution: breathing may be hazardous to your health.
More information about the PyQt
mailing list