问题
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?
回答1:
See the compatibility notes.
For qVariantValue
, use QVariant::value<T>
instead.
index.data().value<SingleItem*>();
来源:https://stackoverflow.com/questions/14919867/qvariantvalue-is-qt-deprecated-what-is-the-replacement