[PyQt] returning SQL result as ordinary python string?
Mark Mordeca
mark.mordeca at prosensus.ca
Thu May 3 13:15:26 BST 2012
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-bounces at riverbankcomputing.com [mailto:
pyqt-bounces at riverbankcomputing.com] *On Behalf Of *Panupat Chongstitwattana
*Sent:* May-03-12 1:14 AM
*To:* PyQt at 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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120503/dc976e65/attachment.html>
More information about the PyQt
mailing list