Reputation: 1715
I have a class "RegistrationList" that keeps a list of pointers to three different types of registrations. I have a function calculateFees() that should return the total registration fees for one of the registration types. I am supposed to use the QT meta object system to check the list for instances of a particular type of registration but when I run the program I get the following error:
C:\Qt\Qt5.3.0\Tools\QtCreator\bin\build-a2-q1-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\moc_registrationlist.cpp:63: error: 'staticMetaObject' is not a member of 'QList' { &QList::staticMetaObject, qt_meta_stringdata_RegistrationList.data, ^
My code for the calculateFees function:
double RegistrationList::totalFees(QString t) {
double total = 0.00;
for (int i = 0; i <= this->size(); ++i) {
if (attendeeList.at(i)->metaObject()->className() == t)
total += this->at(i)->calculateFee();
}
return total;
}
Upvotes: 0
Views: 951
Reputation: 2084
QList is not derived from QObject.
First google result of "error: 'staticMetaObject' is not a member of": Link
What this is saying is that QTreeWidgetItem does not inherit from QObject, meaning that your own, singly-inherited class also does not inherit from QObject. Inheriting from QObject is one of the prerequisites to using the Q_OBJECT macro, which, if you're anything like me, you automatically insert into any Qt GUI related class.
If you're not using any of the meta object stuff in your subclass, such as signals/slots or properties, just take out the Q_OBJECT macro. If you need to use signals and slots, you'll need to make your subclass multiply-inherit from QObject as well. If you take this route, remember that "Multiple Inheritance Requires QObject to Be First", otherwise you'll get either the same error as above, or something along the lines of "YourClass inherits from two QObject subclasses" from the moc.
Replace QTreeWidgetItem
with QList
and there you go.
Upvotes: 2