Search code examples
pythonpyqtpyqt4

Python pyqt database query on a qlist


If you please can help me, I would appreciate it

I'm doing a query of sqlite3 and I want to show the result on a QListWidget

for row in c.execute("SELECT * FROM typem WHERE Type LIKE ?",('%'+'b'+'%',)):
     test = ''
     test += str(row[1])
     print test
     self.listWidget.addItems(test)

On the "print teste" is showing this

On the "print teste" is showing this

And on the "addItems" saves like this

And on the "addItems" saves like this

Can you please help me? Thanks


Solution

  • When you use the addItems() method the QListWidget class assumes that you are passing an iterable so you get each element, and a string is an iterable, so you get that behavior. The solution in your case is to change addItems() to addItem().