‘staticMetaObject’ is not a member

I tried to compile a code looking like this:

#ifndef CONTROLLER_H_
#define CONTROLLER_H_

#include<QObject>

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
{
   ...

 

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

7 Responses

Write a Comment»
  1. Thanks! It was useful for me.

  2. For me to :-) Thanks a lot

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

  4. thx a lot!=v=

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

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

  7. Thank you a lot. Really useful :)

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>