I am working with python plugins.I have one QListWidget as fieldsList_2 on my form.I am listing some item to it, as query result.My code is as follows:
c = self.db.con.cursor()
self.db._exec_sql(c, "SELECT desc,survey from bio")
for row in c.fetchall():
acoustic=unicode(row[0])
if (acoustic[0:3]=="ACO" ):
surv=unicode(row[1])
self.fieldsList_2.addItem(unicode(row[1]))
for i in range(self.fieldsList_2.count):
if self.fieldsList_2.item( i ).text() == surv:
self.fieldsList_2.takeItem( i )
I wanted to prevent QListWidget fieldsList_2 from listing duplicate entries.But when i try to run the above code ,it gives error:
for i in range(self.fieldsList_2.count):
TypeError: range() integer end argument expected, got builtin_function_or_method.
I tried range(1,self.fieldsList_2.count)..but no success.If 3 same items exist,then i wanted to keep one of them into Qlistwidget.
To fix the error message given, try changing from
to
count()-1 because the element you just added was added to the end of the list, and if you wish to keep one you should ignore the last.
An alternative is to only add an item if no duplicate exists, here is some pseudo code: