bullflag
bullflag

Reputation: 109

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

Looking in .cpp file

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'

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>'

Found similar Stackoverflow query

OK ... so what is the replacement?

Upvotes: 0

Views: 549

Answers (1)

When the definition is parsed, QVariant is a known type. But when the declaration is parsed, QVariant is not known yet. As such, the declaration is invalid and the compiler can't but ignore it.

Add #include <QVariant> to the header file to fix that.

It broke, because some Qt headers used to include <QVariant>, and you implicitly depended on that. 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. Thus your broken code has got its bug exposed.

Upvotes: 3

Related Questions