qVariantValue is “QT_DEPRECATED” - what is the replacement?

有些话、适合烂在心里 提交于 2019-12-23 18:11:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!