while(query.next()):

     idString=str(query.value(0).toString())

     passwordString=str(query.value(1).toString())



query.value()  returns a QVariant, so you use .toString() to convert it to
a QString, then use str to convert the QString to a python string.



Hope this helps.



*From:* pyqt-boun...@riverbankcomputing.com [mailto:
pyqt-boun...@riverbankcomputing.com] *On Behalf Of *Panupat Chongstitwattana
*Sent:* May-03-12 1:14 AM
*To:* PyQt@riverbankcomputing.com
*Subject:* [PyQt] returning SQL result as ordinary python string?



Most example I was able to find were putting sql data into PyQt list/table
widgets. But I wasn't able to find example to do basic query. Can anyone
help give me some basic please?

For example, if I query selecting from a table with 3 records

  query = QtSql.QSqlQuery(db)

  query.exec_("SELECT id, password FROM user")

How do I access each record and return them as ordinary Python strings and
not QString?
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to