Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

python - "TypeError: native Qt signal is not callable" with custom slots

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...