QtSql (from PyQT) seems to be broken

1.6k views Asked by At

I cannot access mysql server (on localhost). Python 3.1 & latest PyQt

my code:

from PyQt4 import QtSql
db = QtSql.QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("localhost")
db.setDatabaseName("test")
db.setUserName("root")
db.setPassword("admin")
db.open() #this always returns true. why?

P.S. I'm beginer.

1

There are 1 answers

0
Lennart Regebro On BEST ANSWER

It always returns True, or it always returns False? Make up your mind.

Anyway, the docs says:

Opens the database connection using the current connection values. Returns true on success; otherwise returns false. Error information can be retrieved using lastError().

So if it always returns False, that's because it couldn't open the database. Call db.lastError() to have it tell you why.