Why does staticMetaObject.className() return the class name of the parent class?

StackOverflow https://stackoverflow.com/questions/15811266

  •  01-04-2022
  •  | 
  •  

سؤال

I have a class 'Default' derived from a class 'Units' and when I do:

Default::staticMetaObject.className())

it returns Units instead of Default. Why is that? How can I fix this?

هل كانت مفيدة؟

المحلول

Turning my comment into an answer.

This usually happens when you forget to put the macro Q_OBJECT into the derived class.

From the point of view of Qt's meta-type system, that class is then indistinguishable from its parent class (that is, from the nearest parent class which does have Q_OBJECT inside).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top