无法连接到Python发出的QML中的信号
我有一个用Python创建的无法连接到Python发出的QML中的信号,python,qml,pyside2,Python,Qml,Pyside2,我有一个用Python创建的QQuickItem类: 类MyPage(QQuickItem): def uuu init uuu(self,parent=None)->None: super()。\uuuu init\uuuu(父级) 遇到错误=信号(str) @QtCore.Slot(QUrl,结果=无) def load_报告(自身,文件路径:QUrl)->无: 打印(f“用:{file_path}调用”) 遇到self.error\u.emit(“噢!”) 上述类别注册为: qmlReg
QQuickItem
类:
类MyPage(QQuickItem):
def uuu init uuu(self,parent=None)->None:
super()。\uuuu init\uuuu(父级)
遇到错误=信号(str)
@QtCore.Slot(QUrl,结果=无)
def load_报告(自身,文件路径:QUrl)->无:
打印(f“用:{file_path}调用”)
遇到self.error\u.emit(“噢!”)
上述类别注册为:
qmlRegisterType(MyPage,“MyPage”,1,0,“MyPage”)
我的QML看起来像:
MyPage {
signal errorEncountered(string text)
Component.onCompleted: error_encountered.connect(errorEncountered)
onErrorEncountered: console.log(text)
}
但是,我得到以下错误:
qrc:/qml/main.qml:93:ReferenceError:error\u遇到的错误未定义
PySt2连接到QML到源代码的信号模式在Python中有点不同于C++,而且我很难找出它。在C++中,我会有一个信号定义为
类MyPage(QQuickItem):
遇到错误=信号(str)#无:
super()。\uuuu init\uuuu(父级)
@QtCore.Slot(QUrl,结果=无)
def load_报告(自身,文件路径:QUrl)->无:
打印(f“用:{file_path}调用”)
遇到self.error\u.emit(“噢!”)