QVarian::type, QVarian::typeId and QMetaType
I need to support a codebase for Qt 5.15 LTS and Qt 6.2 LTS.
One of the last issues is QVariant::type().
The type of QVariant was deprecated back in 5.x from an enum inside QVariant in favor of QMetaType.
And for some time now I have been casting the return value to QMetaType for compatibility with Qt 6.0:
QMetaType::Type t = (QMetaType::Type)myqvariant.type();
The line above works with 5.15 and 6.0.
However, Qt 6.3 broke this by removing the method QVariant::type() entirely.
I now have to use QVariant::typeId(), which is equivalent to QVariant::metaType().id().
However, neither typeId() nor metaType() exist in 5.15.
That forces me to litter my code with preprocessor defines to distinguish between 5.15 and 6.3, just to get the type in the same format.
Is there any way to find a compromise that gets me the type of the QVariant in a way that works with 5.15 and 6.3?
Re: QVarian::type, QVarian::typeId and QMetaType
Quote:
That forces me to litter my code with preprocessor defines
Can you use a C++ macro instead, which has different definitions based on the preprocessor switches? Alternatively, can you define an adapter class or class template that takes a QVariant reference as argument and returns the needed type?
In either case, the preprocessor switching is hidden away inside the implementation, but it will still require editing all the code that uses it.
Re: QVarian::type, QVarian::typeId and QMetaType
I will probably have to do that, was hoping I had overlooked a nice way out.
It's really a shame type() was dropped, especially after compatibility was maintained from 5.x -> 6.0...