PDA

View Full Version : QMetaObject::indexOfMethod (const char*) - Does Not Work for Normal methods !!!



Vijaygs
19th June 2013, 18:56
I have the following class

class Test : public QObject
{
Q_OBJECT

public:
int testMethod(int);
virtual int testMethod2(int);

public slots:
void run();

....
};

When i tried to print all the method signatures, by traversing through the list of methods using the MetaObjects' indexofMethod() call, only the run is being displayed and all other methods are not displayed.

When i specifically passed the signature of the "testMethod(int)" to get the index, i get a return value of -1. But if i add the Q_INVOKABLE macro before those 2 functions then all the three methods are displayed through and each has an index. Why is this behavior, there is no information given in the module documentation about the need for Q_INVOKABLE to make the MetaMethod to work for a method inside an object of QObject type. Any help will be appreciated.


Thanks,
vijay

ChrisW67
20th June 2013, 01:38
From QMetaObject Detailed Description:


method() and methodCount() provide information about a class's meta-methods (signals, slots and other invokable member functions).

and "invokable" links to Q_INVOKABLE in the QObject docs. QMetaMethod specifically documents:

A method will only be registered with the meta-object system if it is a slot, a signal, or declared with the Q_INVOKABLE macro. Constructors can also be registered with Q_INVOKABLE.