Matthew Brzezinski
Matthew Brzezinski

Reputation: 1794

PyQt TypeError connect()

I'm very new to Python, so I'm sorry ahead of time if this is a simple mistake.

class TaskTabs(QtGui.QTabWidget):
    ...(some init stuff here)....
    def remove(self):
        self.removeTab(0)
        self.addTab(Tabs.General(self.nao, self.parent), 'General')

In another class:

self.taskTabs = TaskTabs(self.nao, mainWidget)
....(Some other stuff here)....
loadEmpathy = QtGui.QAction(QtGui.QIcon(), '&Load Empathy', self)
loadEmpathy.setShortcut('Ctrl+E')
loadEmpathy.triggered.connect(self.taskTabs.remove())

There error that I am getting is:

TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'

What I am trying to do is to remove a tab in my GUI and add in various ones (which I'll implement later, just testing this now) from a menu. My menu code works perfectly, and now I want to set an action for what happens when it's clicked. I created this remove method in my TaskedTabs file, the remove function works great in my init function, but I want to separate it (for purposes later on). Can anyone explain what is wrong with my code?

Upvotes: 0

Views: 552

Answers (1)

Junuxx
Junuxx

Reputation: 14251

As the error message says, connect() needs a callable method. But what you are giving it is the result of a method, because you're calling it. remove() returns None, which is then used as the argument for connect(), which doesn't work. Solve this by removing the brackets after remove.

loadEmpathy.triggered.connect(self.taskTabs.remove)

Upvotes: 2

Related Questions