(1)起因是看到 Qt 的官方源代码里有这样的写法:
#if QT_DEPRECATED_SINCE(6, 0) //里面的都是废弃的成员函数
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QT_DEPRECATED_VERSION_X_6_0(
"Use the constructor taking a QMetaType instead.")
explicit QVariant(Type type) : QVariant(QMetaType(int(type))) {}
QT_DEPRECATED_VERSION_X_6_0("Use typeId() or metaType().")
Type type() const
{ int type = d.typeId();
return type >= QMetaType::User ? UserType : static_cast<Type>(type);
}
QT_DEPRECATED_VERSION_6_0
static const char *typeToName(int typeId)
{ return QMetaType(typeId).name(); }
QT_DEPRECATED_VERSION_6_0
static Type nameToType(const char *name)
{ int metaType = QMetaType::fromName(name).id();
return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
}
QT_WARNING_POP
#endif //#if QT_DEPRECATED_SINCE(6, 0)
(2) 所以编写例子测试以下:
(3)所以,这样的函数,就不要在新版本里使用了。
谢谢