Qcombobox.addItems: called with Wrong argument types

Asked

Viewed 51 times

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 function return getJson go to the QComboBox which I created, however, when running the code, this error message appears:

Typeerror: 'Pyside.QtGui.Qcombobox.addItems' called with Wrong argument types: PySide.QtGui.QComboBox.addItems(method)

How do I make for the addItems receive the return of the method without giving this error?

  • the return of getjson shouldn’t be a json string?

  • and isn’t it? My code looked like this: self.option = Qcombobox(self) self.data = {'image' ['Planet.jpg', 'cat.png', 'building.jpg']} self.option.addItems(self.data['image'])

  • Attention to @zekk’s response below, I think it solves the problem

  • I saw @Miguel , but I want to modularize the code.

  • 1

    I think I know what’s going on, so try this self.option.addItems(self.getJson()) . Parentheses were missing I think

  • gave! thanks @Miguel

Show 1 more comment

1 answer

3


According to the 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 function result into a variable and pass it to the 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']
  • I had done so, until then, all right, but I want to modularize the code, leaving specific functions for each case..

  • @Alexandremartinsmontebelo See if another way suits your case.

  • I managed, in case it lacked only the parentesesnda call to function getJson inside addItems, then it worked ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.