简体   繁体   English

python pyqt4组合框

[英]python pyqt4 combobox

I am working with python plugins.I designed my form using pyqt4 designer.It has one combobox. 我正在使用python插件。我使用pyqt4设计器设计了表单,它具有一个组合框。 I coded in python as follows: 我在python中编码如下:

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 : 我将数据库中的所有列值都列出到combobox中, 但是self.comboBox.addItem(row)给出错误提示:

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. 即使仅在SQL SELECT子句中选择一个值, fetchall()方法也会产生元组。 Change your code to: 将您的代码更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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