简体   繁体   中英

python pyqt4 combobox

I am working with python plugins.I designed my form using pyqt4 designer.It has one combobox. I coded in python as follows:

self.db._exec_sql(c, "SELECT  "+column_name1+" from  "+table_name+" ")

    for row in c.fetchall():
             print row
             self.comboBox.addItem(row)

row gives me all the values of specific column of specific table. I am listing all column values from database into combobox.But self.comboBox.addItem(row) gives error saying :

TypeError: arguments did not match any overloaded call:
 QComboBox.addItem(QString, QVariant userData=QVariant()): argument 1 has unexp
ected type 'tuple'


 QComboBox.addItem(QIcon, QString, QVariant userData=QVariant()): argument 1 ha
s unexpected type 'tuple'

How do i list values in combobox??

fetchall() method yields tuples, even when you select only one value in the SQL SELECT clause. Change your code to:

for row in c.fetchall():
    self.comboBox.addItem(row[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM