Lupdate error: Qualification with unknown namespace / class

I came across a very strange error using lupdate v4.7.2. I got an error message

module / foo.cpp: 6: Qualification with an unknown namespace / class :: foo

for several classes in a project with approximately 50 classes. I welded the problem to a simple example:

CSI / project.pro:

QT += core TARGET = test TEMPLATE = app SOURCES += main.cpp \ screen.cpp HEADERS += screen.h TRANSLATIONS += de.ts 

Src / module / foo.h:

 namespace sp { class foo { initWidgets(); }; } // namespace sp 

Src / module / foo.cpp:

 #include <QString> #include "module/foo.h" namespace sp { foo::initWidgets() { QString bar = tr("bar"); } } // namespace sp 

main.cpp has an empty main function in it.

Compiling the code (banning any copypasta errors that I could create here), so the syntax is mostly correct.

+4
source share
5 answers

The answer was that lupdate could not find the header file foo.h while parsing foo.cpp. The .pro file extension with the following line fixed the problem:

 INCLUDEPATH += . 

However, what bothers me a bit, the compiler should not have compiled the code, but somehow qmake added -I. to the compiler options. This is why I did not think about the problem with the included file before and spent a couple of hours puzzling this. Does anyone know if this is the default behavior? Also: Why does lupdate not display the corresponding error message?

+6
source

In my case, lupdate could not parse the enum MyEnum: int {}; and failed to get the class declaration. Qt 5.7.1, lupdate still does not understand type specifiers for enumerations.

+2
source

I received the same message in another scenario. In my case, the problem was that foo.cpp contained #include <foo.h> instead of #include "foo.h" . Since both files were a directory that was not included in the global include path, lupdate did not bother to search in this directory due to the absence of quotation marks in include. Switching to appropriate include delimiters made lupdate happy.

+1
source

I also saw this error message using Qt 5.4.1 on a Ubuntu 12.04 system.

But the cause of the error was different. "lupdate" seems to have problems with strong C ++ - 11 enumerations, at least when using related forward declarations encapsulated in a namespace.

I use something like this in the corresponding header file:

 namespace outer { namespace other { enum class MyEnum : int; } // namespace outer::other namespace inner { class MyClass { //... }; } // namespace outer::inner } // namespace outer 

The problem with "lupdate" can be solved with marco for the term "enum class":

 #ifndef ENUM_CLASS #define ENUM_CLASS enum class #endif namespace outer { namespace other { ENUM_CLASS MyEnum : int; } // namespace outer::other namespace inner { class MyClass { //... }; } // namespace outer::inner } // namespace outer 
0
source

In my case, there was a strange (but legally, I guess) formatted type declaration in the structure before the actual class declaration. This made lupdate skip the class and led to a "unconditional" warning. The code looked like this (was not mine to start with ;-)):

 struct coords_t { double x, y; ... }; struct plotsCollection { QVarLengthArray<struct coords_t> coords; // problem right here ... }; class LogsDialog : public QDialog { Q_OBJECT ... } 

Removing a struct from QVarLengthArray<struct coords_t> resolved the warning. Structure declarations also moved within the class. I did both :)

0
source

All Articles