Non-Qt Base Classes
I'm using Qt (which I'm new to) 4.8.2, with Visual Studio, and I have created a base class named "Contact". I don't want this class to be Qt-exclusive, so my intention was to make another class "QContact" that will inherit "Contact", and QObject and deal with all the Qt-related business, such as the Q_OBJECT macro etc.
Unfortunately when I inherited, the build failed, saying:
moc_QContact.cpp(53): error C2039: 'staticMetaObject' : is not a member of 'Contact'
moc_QContact.cpp(75): error C2039: 'qt_metacast' : is not a member of 'Contact'
moc_QContact.cpp(80): error C2039: 'qt_metacall' : is not a member of 'Contact'
I did a little research on the web and found out that you can't derive a Qt class from non-Qt class. so to fix it, "Contact" could inherit "QObject" (I tried, it worked). but doing so will make it exclusive to Qt which is my problem.
So what I ask is this: How can you make a non-Qt base class for a Qt class?
Thank you.
You can derive your class from QObject
and from other classes that don't derive from it, but QObject
needs to be the first base class in the base classes list.
So this is wrong:
class QContact: public Contact, public QObject {};
You need to write it as
class QContact: public QObject, public Contact {};