QComboBox.addItems: called with wrong argument types

2

I have the following code:

self.option = QComboBox(self)
self.option.addItems(self.getJson)

def getJson(self):
    self.data = {'image' : ['planet.jpg', 'cat.png', 'building.jpg']}

    return self.data['image']

I want to make the return of the getJson function go to the QComboBox that I created, however, when I run the code, this error message appears:

  

TypeError: 'PySide.QtGui.QComboBox.addItems' called with wrong   argument types:   PySide.QtGui.QComboBox.addItems (method)

How do I get addItems to return the method without giving this error?

    
asked by anonymous 22.08.2016 / 20:06

1 answer

3

According to documentation , a list is expected, you are passing a function.

Pass the list directly:

self.option = QComboBox(self)
self.data = {'image' : ['planet.jpg', 'cat.png', 'building.jpg']}

self.option.addItems(self.data['image'])

Another way is to put the result of the function into a variable and pass it to QComboBox :

self.option = QComboBox(self)
self.json = self.getJson()

self.option.addItems(self.json)

def getJson(self):
    self.data = {'image' : ['planet.jpg', 'cat.png', 'building.jpg']}

    return self.data['image']
    
22.08.2016 / 20:11