简体   繁体   English

未声明的标识符“ QVariant”将旧版Qt 4转换为5

[英]Undeclared identifier 'QVariant' convert legacy Qt 4 to 5

I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in Qt Creator 4.2.1 Clang 7.0(Apple) 64bit 我需要将Qt旧版代码从4.7转换为5.8,我在Qt Creator 4.2.1 Clang 7.0(Apple)64位中遇到编译错误

Looking in .cpp file 在.cpp文件中查找

bool queries::insert(const QString &tableName_, const QMap<QString, QVariant> &values_) const

Error in .cpp ./src/classes/queries.cpp:283:15: error: out-of-line definition of 'insert' does not match any declaration in 'queries' Error pointing to 'insert' .cpp ./src/classes/queries.cpp:283:15中的错误错误:“插入”的脱机定义与 “查询”中的任何声明都不匹配指向“插入”的错误

Looking in the header file 在头文件中查找

bool insert(const QString &tableName_, const QMap<QString, QVariant> &values_) const;

Error in .h ../src/classes/queries.h:157:64: error: use of undeclared identifier 'QVariant' Error pointing to 'QVariant>' .h ../src/classes/queries.h:157:64中的错误错误:使用未声明的标识符'QVariant'指向'QV​​ariant>' 错误

Found similar Stackoverflow query 找到类似的Stackoverflow查询

OK ... so what is the replacement? 好...那是什么替代品?

When the definition is parsed, QVariant is a known type. 解析定义时, QVariant是已知类型。 But when the declaration is parsed, QVariant is not known yet. 但是,当解析该声明时, QVariant还未知。 As such, the declaration is invalid and the compiler can't but ignore it. 因此,该声明无效,编译器只能忽略它。

Add #include <QVariant> to the header file to fix that. #include <QVariant>添加到头文件中以修复该问题。

It broke, because some Qt headers used to include <QVariant> , and you implicitly depended on that. 它破裂了,因为某些Qt标头曾经包含<QVariant> ,而您隐式地依赖<QVariant> As Qt has been updated, such interdependencies were minimized and the headers now only include the minimum necessary to make them valid if compiled in a free-standing translation unit. 随着Qt的更新,这种相互依赖性已被最小化,并且标头现在仅包含在以独立翻译单元进行编译时使其有效所必需的最小值。 Thus your broken code has got its bug exposed. 因此,您的破损代码暴露了其错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM