PDA

View Full Version : How can I call a C++ function knowing its function string?



lni
1st December 2013, 10:55
Hi,

If some one tells me there is a c++ member function, say "foo". How can I use Q_GADGET (not Q_OBJECT) to call this function?

MyClass obj;
obj.foo();

However, foo is passed to me by QString "foo". The only thing I am told is that foo return void and has no argument.

Any help is appreciated.

anda_skoa
1st December 2013, 15:51
I don't think you can do that with Q_GADGET.
At least QMetaObject::invokeMethod() always requires a QObject* as the "receiver" object.

Cheers,
_

ChrisW67
2nd December 2013, 05:43
Q_GADGET only provides access to class enums that are declared with Q_ENUMS. It does not make the class a QObject, provide signals/slot support, or allow you to mark a function Q_INVOKABLE.



If some one tells me there is a c++ member function, say "foo".
...
However, foo is passed to me by QString "foo". The only thing I am told is that foo return void and has no argument.

Unless SomeClass::foo() is static there is no way that you can call a member function without a QSomeClass object. A non-static member function has one implied argument, the pointer to the object it is to act on.