sashoalm sashoalm - 2 months ago 21
C++ Question

Why does QVariant::type() return a QVariant::Type when it should be interpreted as a QMetaType::Type?

The docs about QVariant::type() say that:

Returns the storage type of the value stored in the variant. Although this function is declared as returning QVariant::Type, the return value should be interpreted as QMetaType::Type. In particular, QVariant::UserType is returned here only if the value is equal or greater than QMetaType::User.

Well, if so, why didn't they declare it as returning
in the first place? That way it seems only to bring needless confusion.

The docs don't explain the reasons for declaring the function to return the wrong type, does anyone know what those reasons might have been?


First there was QVariant with a type enum for supported types. Then there came QMetaType with its own type enum for supported types.

So QVariant was changed, the types aligned, so that its own type enum could be deprecated and it would depend on QMetaType for type information. However, for source compatibility reasons the return type could not be changed.

The return type might be changed for Qt6 but source incompatible changes are decided by case so there have to be discussions about the impact and benefits of the change.