私のクラスのScanQrCode()からcalss MainDialog()に信号を戻すにはどうすればよいですか?私はQtDesigner4によって生成されたウィンドウでPython 2.7とPyQtを使用しています。 私はクラスScanQrCode()内の信号をクラス内の受信関数にも送ることができました。しかし、私は別のクラスのMainDialog(でそれを受け取るしようとすると、信号が失われる)が、同じファイルPyQtクラス(サブウィンドウ)からMainWindow(クラス)に返信する
class ScanQrCode(QtGui.QDialog, Ui_ScanQrCode):
trigger = QtCore.pyqtSignal()
def __init__(self, parent = None):
super(ScanQrCode, self).__init__(parent)
self.setupUi(self)
self.pushButton_Scan.clicked.connect(self.scan)
# End of __init__
def scan(self):
print 'Scanning'
# Place holder for the functionality to scan the QR code
self.lineEdit_QrCode.setText("QR-123456789") # Dummy QR code
if (not self.signalsBlocked()):
print 'emit trigger'
self.trigger.emit()
# End of sub-function scan
# End of class ScanQrCode
class MainDialog(QtGui.QMainWindow, agpt_gui.Ui_MainWindow):
def __init__(self, parent = None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
self.connectActions()
self.windowScanQrCode = None
#Define threads
self.thread = ScanQrCode()
self.thread.trigger.connect(self.updateQrCode)
# end of __init__
def main(self):
self.show()
def connectActions(self):
# Define the connection from button to function
self.pushButton_ScanQrCode.clicked.connect(self.scanQrCode)
self.pushButton_Exit.clicked.connect(self.exit)
# End of sub-function connectActions
@QtCore.pyqtSlot()
def updateQrCode(self):
"""
Update the new scanned QR code in the main window
"""
print 'Update QR code'
self.lineEdit_QrCode.setText("123456789")
# End of sub-function updateQrCode
def scanQrCode(self):
if self.windowScanQrCode is None:
self.windowScanQrCode = ScanQrCode(self)
self.windowScanQrCode.show()
# End of sub-function scanQrCode
# End of class MainDialog
にエラーはありません。単にメインウィンドウは更新されません。 私は原則としてシグナルと接続が機能していると思うが、見えないものがなければならない。 ご協力いただければ幸いです。