‘staticMetaObject’ is not a member

I tried to compile a code looking like this:

#ifndef CONTROLLER_H_
#define CONTROLLER_H_

#include

class AbstractClass
{
public:
    virtual ~AbstractClass() {}
    virtual void update() = 0;
};

class Controller :
      public AbstractClass, public QObject
{
      Q_OBJECT

public:
      Controller();
      virtual ~Controller();
      virtual void update();

public slots:
      void m();
};

#endif /*CONTROLLER_H_*/

If you’re trying to compile it you get an error:

tmp/moc/moc_Controller.cpp:45: error: 'staticMetaObject' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual void* Controller::qt_metacast(const char*)':
tmp/moc/moc_Controller.cpp:61: error: 'qt_metacast' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual int Controller::qt_metacall(QMetaObject::Call, int, void**)':
tmp/moc/moc_Controller.cpp:66: error: 'qt_metacall' is not a member of 'AbstractClass'
make: *** [tmp/objects/moc_Controller.o] Error 1

The error is caused by a bad order of inheritance.

Instead of this

class Controller :
	public AbstractClass, public QObject
{
   ...

you should use this

class Controller :
	public QObject, public AbstractClass
{
   ...

 

18 Comments

  1. Anonymous

    Thanks! It was useful for me.

  2. Ralf

    For me to :-) Thanks a lot

  3. baltazar

    Useful information, thank you! I had exactly the same problem and now it’s fixed.

  4. Delly

    thx a lot!=v=

  5. Andrew

    thanks a lot! This was useful. Though, I don’t understand why this problem arises. What does inheritance order influence upon?

  6. slopjong

    I don’t know why the compiler behaves like that. I’m not a C++ expert :-(

  7. nikolakoco

    Thank you a lot. Really useful :)

  8. Hadi

    thank you very much.
    I have this problem and your good comment help me.
    thank you again.

  9. Anand Swaroop

    Thanks !

  10. Prdel

    Thank you!

  11. Luis

    Thank You!

  12. Nilupul

    Thank you. You solved one of my great headache.

  13. Ehsan

    man , you just Blow My Mind … What sorcery is this ?!
    Thanks ..
    Thank U Very Much …!!!

  14. .. or your inherited class is not a QObject.
    e.g.: QRunnable is NOT a QObject
    class Example : public QObject, public QRunnable
    should do it

  15. Ile

    Thanks a lot

  16. evgeny_sl

    Thank U, Man! Right on the button!

  17. Nadun

    Thanks a lot..!!! You saved lot of time.. :)

  18. George

    Thank you! saved me!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>