カスタム クラスでスロット/シグナルを使用しようとすると、いくつかの問題が発生します。
クラスは次のようになります。
import sys
from PyQt5 import QtCore
from PyQt5.QtGui import QGuiApplication, QPixmap
class Screenshot(QtCore.QObject):
newScreenshotTaken = QtCore.pyqtSignal(QPixmap)
timer = QtCore.QTimer()
captureInterval = 5 * 60
def __init__(self):
super(Screenshot, self).__init__()
def startCapture(self):
self.capture()
def stopCapture(self):
self.timer.stop()
def on_userStartedCapture(self):
self.startCapture()
def on_userStoppedCapture(self):
self.stopCapture()
def capture(self):
print("capture!")
エラーは on_userStartedCapture(self) で発生します。
File "/Volumes/HD2/test/screenshot.py", line 23, in on_userStartedCapture
self.startCapture()
AttributeError: 'NoneType' object has no attribute 'startCapture'
Emit は別のクラスから呼び出されます。
self.userStartedCapture.emit()
そして接続は main.py で行われます:
screenshot = Screenshot()
mainWindow = MainWindow()
mainWindow.userStartedCapture.connect(screenshot.on_userStartedCapture)
奇妙なことに、アプリケーションのすべてのスロット/シグナルで self が機能します。しかし、なぜこの特定のものが失敗しているのかわかりません。
何が起こっているのかについてのアイデアはありますか?