Solved 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.
-
Many thanks!
-
Dear @liubbc,
Could you please mark this topic to SOLVED
Thanks a lot ;) -
@sierdzio Many Thanks
-
@Alien So sorry, i try many times , but how to translate UNSOLVED to SOLVED ?
-
@liubbc your welcome,
click on "Topic Tools" button on right bottom of the page and then select the "Mark as solved"
have a nice day