Unknown method parameter type: QString&
-
Hi, Qters
When QML call C++ class function, an error occur :
Unknown method parameter type: QString&The code snippet are :
//calculator.h class Calculator : public QObject{ public: Q_INVOKABLE QString getResult(QString & leftValue, QString & rightValue); } //calculator.cpp QString Calculator::getResult(QString & leftValue, QString & rightValue){ return "abc"; } //qml Calculator{ id: calculator; } display.text = calculator.getResult("abc", "bcd");if class Calculator getResult function is defined :
class Calculator : public QObject{ public: Q_INVOKABLE QString getResult(QString leftValue, QString rightValue); }the error disappeared.
but i do not know the root cause. Does anybody know the reason ? Thanks in advance !
[edit: sierdzio. Added code tags]
-
QML connections are handled via MOC in Qt, which places strict rules on parameters - to prevent problems in threads. More info.
When a function is called via Q_INVOKABLE (or it is a slot), parameter is always passed by value (copy ). Const references also work.
-
QML connections are handled via MOC in Qt, which places strict rules on parameters - to prevent problems in threads. More info.
When a function is called via Q_INVOKABLE (or it is a slot), parameter is always passed by value (copy ). Const references also work.