2015-09-16 3 views
0

У меня есть класс «RegistrationList», который хранит список указателей на три разных типа регистрации. У меня есть функция calculateFees(), которая должна вернуть общую регистрационную плату за один из типов регистрации. Я должен использовать систему метаобъектов QT для проверки списка экземпляров определенного типа регистрации, но когда я запускаю программу, я получаю следующую ошибку:Ошибка Strange QMetaObject

C: \ Qt \ Qt5.3.0 \ Tools \ QtCreator \ Bin \ билд-a2-q1-Desktop_Qt_5_3_0_MinGW_32bit-Debug \ Debug \ moc_registrationlist.cpp: 63: ошибка: 'staticMetaObject' не является членом '' QList {& QList :: staticMetaObject, qt_meta_stringdata_RegistrationList.data, ^

Мой код для функции calculateFees:

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; 
} 
+0

просто указывающий, что в цикле 'for' это должно быть i < this-> size(), а не <= – Anorflame

ответ

2

QList не получен из QObject.

Первый Google результат "Ошибка: 'staticMetaObject' не является членом": 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.

Заменить QTreeWidgetItem с QList и там вы идете.