Reputation: 31
I am trying to call a function in my QML:
function resetSomething() {
tempVar= undefined
}
I am not sure how to write the invokeMethod for this function. I tried using something like that:
QQuickItem* qObj= findChild<QQuickItem>("temp");
if (qObj)
{
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething",Q_RETURN_ARG,QVariant,returnArg));
}
But it gives the error
no matching function resetSomething(QVariant) found.
Upvotes: 2
Views: 314
Reputation: 1177
As you can see in your error message Qt's Meta Object System is trying to find method resetSomething(QVariant), but your method doesn't have any parameters. I guess it's because of wrong Q_RETURN_ARG macro usage.
Seems that you can simply fix it like this:
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnArg));
Also I suggest you to read official Qt documentation, it is brilliant.
BTW: Nice repo from Google with a lot of C++/JavaScript intercommunication. You can find a lot of useful patterns there.
Upvotes: 1