简体   繁体   English

在pyqt4 qobject类中连接pyqt4信号

[英]connecting pyqt4 signals in a pyqt4 qobject class

I've got two classes; 我有两节课; one for my window and one for my controlling object 一个用于我的窗口,一个用于我的控制对象

class window(baseClass, testForm):
    scanStarted = QtCore.pyqtSignal(str)
    def __init__(self,parent=None):
        super(window, self).__init__(parent)
        self.setupUi(self)

        #other window setup
        self._scanner.pushScan.clicked.connect(self._scanClicked)

    def _scanClicked(self):
        self.scanStarted.emit( self._scanner.getTextData() )

and my controlling object 和我的控制对象

class vis(QtCore.QObject):
    def __init__(self):
        self._oreList = []

        self._w = window()
        self._w.scanStarted.connect(self._scanOre)

    def _scanOre(self, rawText):
        print "main ->", rawText

When using the QtCore.QObject as my reference, this signal won't connect to the _scanOre. 使用QtCore.QObject作为参考时,此信号将不会连接到_scanOre。 When I switch the reference to python 'object' it'll work fine. 当我将引用切换为python'object'时,它将正常工作。 I've been trying to figure out why it won't connect using the QtCore.QObject type. 我一直试图弄清楚为什么它不会使用QtCore.QObject类型连接。

The signal will also connect just fine in the window class regardless. 无论如何,信号也会在窗口类中正常连接。

I tried giving the _scanOre the @QtCore.pyqtSlot(str, name='scanGo') and adding the name parameter into the signal creation as well. 我尝试给_scanOre @ QtCore.pyqtSlot(str,name ='scanGo')并将name参数添加到信号创建中。 I'm not sure what I'm missing here. 我不确定我在这里缺少什么。

You forgot to initialize the QObject : 你忘了初始化QObject

class vis(QtCore.QObject):
    def __init__(self, parent=None):
        super(vis, self).__init__(parent) # you are missing this line
                                          # also the `parent` arg
        self._oreList = []

        self._w = window.window()
        self._w.scanStarted.connect(self._scanOre)

    def _scanOre(self, rawText):
        print "main ->", rawText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM