I have one function declared in Foo
class:
Q_INVOKABLE void setImageUrl(const QString &imageUrl);
However I cannot get the function index of that method:
Foo* foo = new Foo();
const QMetaObject* metaObject = foo->metaObject();
QString functionNameWithparameter("setImageUrl(QString)");
int functionIndex = metaObject->indexOfMethod(functionNameWithParameter.toStdString().c_str());
if (functionIndex >= 0) {
// never the case
}
What am I missing?
Apart from the two compiler errors, your approach seems to be correct. I assume that you had some changes that required to rerun moc, but you have not actually done so. This is the working code for me.
main.cpp
main.pro
Build and Run
Output