我在QML中定义了以下插槽:
onTextResourceFileToReadChanged: {
// textArea.text = "Hello world!" // Works, sets text as expected
textArea.text = TextResourceReader.hello_world() // Doesn't work: "Error: Cannot assign [undefined] to QString"
}
我在Python中定义了以下插槽:
class Foo(QtCore.QObject):
def __init__(self, parent=None):
super().__init__(parent)
@QtCore.Slot()
def hello_world(self):
return "Hello world!"
我的Python类已注册:
engine.rootContext().setContextProperty("Foo", foo)
但是,当调用我的QML插槽onTextResourceFileToReadChanged
时,出现以下错误:
Error: Cannot assign [undefined] to QString