0

Представим, что есть класс, производный об QObject:

class Base : public QObject
{
    Q_OBJECT

public:
    virtual ~Base();
    ...
}

также есть дочерний класс, в котором отсутствует объявление Q_OBJECT

class Child: public Base 
{
    ....
}

корректно ли отработают деструкторы при вызове deleteLater дочернего класса ?

Base* new_child = new Child();
...
child->deleteLater();

И, собственно необходимо ли использовать Q_OBJECT макрос в каждом из наследуемых классов, если эти классы не имеют собственных сигналов/слотов?

1 ответ 1

0

корректно ли отработают деструкторы при вызове deleteLater дочернего класса ?

Да

необходимо ли использовать Q_OBJECT макрос в каждом из наследуемых классов, если эти классы не имеют собственных сигналов/слотов?

Документация рекомендует это делать, так как он используется для свойств и информации о типах (для qobject_cast):

The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system.

Notice that the Q_OBJECT macro is mandatory for any object that implements signals, slots or properties. You also need to run the Meta Object Compiler on the source file. We strongly recommend the use of this macro in all subclasses of QObject regardless of whether or not they actually use signals, slots and properties, since failure to do so may lead certain functions to exhibit strange behavior.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.