“TypeError: native Qt signal is not callable” with custom slots

梦想的初衷 提交于 2019-11-28 05:27:10

问题


The Environment

I am running an Anaconda environment with Python 3.4. I am using PyCharm as my IDE.

The Objective

I am trying to make a pyQt4 QPushButton connect to a custom function:

button.clicked().connect([method reference or whatever])

Attempts

I have tried using the pyqtSlot() decorator but when I run the code it throws:

NameError: name 'pyqtSlot' is not defined

I have used the following imports which should include that decorator:

from PyQt4 import QtCore, QtGui

I also attempted to change my method into its own callable class containing a call method.

The general error message that I'm getting for various attempts is this:

TypeError: native Qt signal is not callable

The Question

Honestly, at this point I have pretty much no idea where to go with this or what details you may need to diagnose the problem. Could anyone give me an idea how to put this together?


回答1:


pyqtSlot() should be imported from PyQt4.QtCore:

from PyQt4.QtCore import pyqtSlot

it can be also used as @QtCore.pyqtSlot() since you already import QtCore.

You have the error message TypeError: native Qt signal is not callable since the slot clicked should be connected without parentheses:

button.clicked.connect([method reference or whatever])

You can start from simple examples that you can find in PyQt4 package, for example examples/widgets/tetrix.py:

    startButton = QtGui.QPushButton("&Start")
    startButton.clicked.connect(self.board.start)



回答2:


object.signal().connect(slot()) should be replaced with object.signal.connect(slot)



来源:https://stackoverflow.com/questions/33049146/typeerror-native-qt-signal-is-not-callable-with-custom-slots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!