Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

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

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMetaObject::indexOfMethod (const char*) - Does Not Work for Normal methods !!!

    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.

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2016, 12:30
  2. Getting const char * from QLineEdit
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 09:28
  3. Connect with const char*
    By grazyna in forum Qt Programming
    Replies: 7
    Last Post: 14th August 2009, 18:13
  4. char to const char* with atof
    By mickey in forum General Programming
    Replies: 5
    Last Post: 29th February 2008, 04:10
  5. QString to const char
    By TheRonin in forum Newbie
    Replies: 2
    Last Post: 12th February 2007, 14:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.