0
のブールオブジェクトを接続しているのは、私はこのコードのスニペットを持っているとしましょう:pyqtSignalは()の代わりにSTR
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import pyqtSignal
from ui_helloworld import Ui_MainWindow
from ui_hellodialog import Ui_Hi
from sys import argv
from sys import exit
class MainWindow(QMainWindow):
update = pyqtSignal(str)
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.h = HelloDialog()
self.ui.pushButton.clicked.connect(self.update_label)
self.ui.doIt.clicked.connect(self.h.update_label)
def update_label(self):
self.h.show()
def update_label_hello(self, msg):
self.update.emit(msg)
class HelloDialog(QDialog):
def __init__(self):
super(HelloDialog, self).__init__()
self.ui = Ui_Hi()
self.ui.setupUi(self)
def update_label(self, msg):
print msg
# Crashes the program:
# TypeError: setText(self, str): argument 1 has unexpected type 'bool'
# >> self.ui.label.setText(msg)
self.ui.label.setText("Hello world!")
def main():
app = QApplication(argv)
window = MainWindow()
window.show()
exit(app.exec_())
if __name__=="__main__":
main()
それはかなり簡単です。 2つのウィンドウ、1つはQMainWindow、もう1つはQDialogです。
pushButton
はHelloDialog
のスロットがupdate
からブールを受信していること、HelloDialog
doIt
が
問題があるupdate
信号を発する開き:メインウィンドウは、2つのボタン押しボタンとのdoItを有します信号はMainWindow
ですが、strオブジェクトとして宣言しました。
update_label
スロットにbool
のオブジェクトがあり、str
のオブジェクトではないのはなぜですか?
localhost :: Documents/Python/qt » python main.py
{ push `doIt` object }
False
Ui_MainWidow
とUi_Hi
クラスはpyuic5
を生成しています。