2

I have a dictionnary fields={} which contains some field names that I named the Qt comobox objects after. For example keys combobox1 and combobox2, both contain a list with values that I would like to add to the

fields={}
fields['combobox1']=['value1','someting else']
fields['combobox2']=['bla','another value']

for key,values in fields.items():
   for value in values:
      Qt_ui. _____key_____ .addItem(value)

what is the correct syntax for the last line, so that ____key____ is replaced with the keys from the dictionary? I tried ui.__getattribute__(key).addItem(value) but it does't seem to work. Any suggestions are appreciated.

TypeError: 'PySide.QtGui.QComboBox.addItem' called with wrong argument types:
  PySide.QtGui.QComboBox.addItem(float)
Supported signatures:
  PySide.QtGui.QComboBox.addItem(PySide.QtGui.QIcon, unicode, QVariant = QVariant())
  PySide.QtGui.QComboBox.addItem(unicode, QVariant = QVariant())
2
  • 1
    The ui.__getattribute__(key) part seems to work. It looks like value is seen as a float. Can you print it before calling Qt_ui....? Commented Mar 31, 2016 at 15:19
  • Yes you are right, it needs to be a string, Problem solved. thanks Commented Mar 31, 2016 at 15:20

1 Answer 1

1

In fact the problem was somewhere else getattribute(key) is correct but the added item needs to be a string. Any way, I thought this is an interesting problem and will leave the post anyway.

ui.__getattribute__(key).addItem(str(value)) 
Sign up to request clarification or add additional context in comments.

1 Comment

getattr(ui, key).addItem(value).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.