Get return value in QML from Python method

后端 未结 1 1324
悲哀的现实
悲哀的现实 2021-01-24 09:18

I\'m trying to call a Python method from QML and use the return value.

QML receives undefined, from the Python method.

When passed back to Python it is just an e

相关标签:
1条回答
  • 2021-01-24 09:46

    You also need to tell what you are returning from your method (pay attention to the result in the pyqtslot decorator:

    class InPython(QObject):
        @pyqtSlot(str, result=str)  # also works: @pyqtSlot(QVariant, result=QVariant)
        def login(self, Login):
            print(Login)
            return "a"
    

    result – the type of the result and may be a Python type object or a string that specifies a C++ type. This may only be given as a keyword argument.

    Documentation about @pyqtslot (and the result parameter)

    0 讨论(0)
提交回复
热议问题