Question

i need to convert Qt legacy code from 4 to 5.1 now i have compilation error in visual studio 2010 :

SingleItem* item = qVariantValue<SingleItem*>(index.data());  

gives me :

.cpp(63): error C2065: 'qVariantValue' : undeclared identifier

when i go to the header i see :

#if QT_DEPRECATED_SINCE(5, 0)
template<typename T>
inline QT_DEPRECATED T qVariantValue(const QVariant &variant)
{ return qvariant_cast<T>(variant); }

template<typename T>
inline QT_DEPRECATED bool qVariantCanConvert(const QVariant &variant)
{ return variant.template canConvert<T>(); }
#endif

ok ... so what is the replacement?

Was it helpful?

Solution

See the compatibility notes.

For qVariantValue, use QVariant::value<T> instead.

index.data().value<SingleItem*>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top