我有一个运行良好的应用程序,但未打开警告进行编译。我正在尝试重新打开它并对其进行分类,但是关于如何解决此问题的想法已用尽。我有 :
QVariant someVar
QVariant::Type variantType = someVar.type();
switch (variantType) {
case QMetaType::QString:
doSomething1();
break;
case QMetaType::Float:
doSomething2();
break;
}
Run Code Online (Sandbox Code Playgroud)
并得到以下警告/错误:
error: case value ‘135’ not in enumerated type ‘QVariant::Type’ [-Werror=switch]
Run Code Online (Sandbox Code Playgroud)
在QMetaType :: Float行中。我检查了QT文档,并将QMetaType :: Float列为值38。这可能是什么引起的?
我可以找到的最接近的东西是https://github.com/qbittorrent/qBittorrent/issues/2510,它具有相同的错误。有人遇到过吗?
在这两个枚举(QMetaType::Type和QVariant::Type)的作用下,Qt发挥了一些肮脏的把戏。引用4.8.4文档QVariant::type():
返回变量中存储的值的存储类型。尽管此函数声明为returning
QVariant::Type,但返回值应解释为QMetaType::Type。特别是,QVariant::UserType仅当值等于或大于时才返回QMetaType::User。请注意,
QVariant::Char贯穿QVariant::RegExp和QVariant::Font贯穿范围内的返回值QVariant::Transform对应于QMetaType::QChar贯穿QMetaType::QRegExp和QMetaType::QFont贯穿范围内的值QMetaType::QQuaternion。还要注意的是类型
void*,long,short,unsigned long,unsigned short,unsigned char,float,QObject*,和QWidget*在代表QMetaType::Type,但不是在QVariant::Type,他们可以通过这个函数返回。但是,在对它们进行测试时,它们被视为用户定义的类型QVariant::Type。
换句话说,该函数QVariant::type()返回QMetaType::Type类型为as的值QVariant::Type,并且这两个枚举共享许多(但不是全部)枚举。这使得在严格类型系统中与它们打交道变得很困难-它们基本上是摇摆不定的,打字不正确的东西。
在您的情况下,请注意,该枚举QMetaType::Float器在中没有直接等效的枚举器QVariant::Type。
我想说,使警告静音的最佳方法是将更variantType改为QMetaType::Type,如有必要,可以使用初始化和/或引用Qt docs的注释进行转换。
| 归档时间: |
|
| 查看次数: |
3241 次 |
| 最近记录: |