[PyQt] Re: Re: How to communicate with mysql?

Hans-Peter Jansen hpj at urpla.net
Sun Jan 27 20:11:21 GMT 2008


Am Sonntag, 27. Januar 2008 schrieb Ryen Lee:
> > > Hi everybody! I am a newbie for PyQT.Now I am write a simple programm
> > > which
> > >
> > > > use mysql as its database,but I find it is very diffucult to use
> > > > the
> > >
> > > PyQT
> > >
> > > > APIs.I write sth like that:
> > > >
> > > > db = QtSql.QSqlDatabase.addDatabase("QMYSQL")
> > > > db.setHostName("127.0.0.1")
> > > > db.setDatabaseName("test")
> > > > db.setUserName("root")
> > > > db.setPassword("123456")
> > > > db.open()
> > > >
> > > > but it just doesn't work. <snip>
> > >
> > >    - Meaning? What does db.open() return, True or False? Does the
> > >    database "test"
> > >    exist? And is Qt configured with MySQL support?
> > >
> > >    Or did you perhaps call these methods before you had created a
> > >    QApplication or
> > >    a QCoreApplication object? That won't work and the error messages
> > >    aren't very
> > >    helpful for this case.
> > >
> > >    I can't test your code, because I don't have MySQL installed.
> > >
> > >    HTH
> > >    Sibylle
> > >
> > >
> > >
> > > --
> > > Dr. Sibylle Koczian
> >
> > Thank you for your reply!
>
>  I try to fix the problem as you told,but I failed finally.I think PyQt
> doesn't support mysql very well,because when I change
> db = QtSql.QSqlDatabase.addDatabase("QMYSQL")
> to
> db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
>
> it works.So I decide to use mysqldb instead of PyQT's APIs

Your logic above doesn't make any sense (for me at least). 

While you're free to use whatever database backend/interface you want, I'm 
inclined to mention, that I use mysql successfully since ages (I did some 
of the PyQt3 examples, when I started) with lots of success. Sure, some API 
details looks arkward from a python perspective due to the underlying C++ 
type system (QVariant and friends), but on the plus side, it's a pleasure 
to create/display a table with 30000 records without problems (neither at 
the memory nor at the slowness front due to some pretty elaborated Qt 
algorithms at work down under). It will take significant developer 
resources to create something on par with the Qt database framework (been 
there, done that for specialized tkinter case).

I cannot imagine, that the situation turned much worse with PyQt4.

Cheers,
Pete



More information about the PyQt mailing list