lupdate error: Qualifying with unknown namespace/class
Asked Answered
S

7

11

I ran into a very peculiar error using lupdate v4.7.2. I got the error message

module/foo.cpp:6: Qualifying with unknown namespace/class ::foo

for a couple of classes in a project with about 50 classes. I boiled the problem down to a simple example:

src/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.

The code compiles (barring any copypasta mistakes I might have produced here), so the syntax is basically correct.

Sodden answered 28/6, 2011 at 10:16 Comment(1)
You're missing a return type for initWidgets();Festschrift
S
11

The answer was that lupdate was unable to locate the header file foo.h while parsing foo.cpp. Extending the .pro file with the following line removed the issue:

INCLUDEPATH += .

However, what still bothers me a bit is that the compiler should have been unable to compile the code, but somehow, qmake added a -I. to the compiler options. That's why I didn't think of an include file issue earlier and spent a couple of hours puzzling this out. Does anyone know whether this is default behavior? Also: Why does lupdate not emit an appropriate error message?

Sodden answered 28/6, 2011 at 19:38 Comment(2)
I had the same problem, your solution did not work for me straight away but pointed me in the right direction. According to this bug report, the root of the problem is that lupdate searches for include files relative to the current directory. In my case, I had to add INCLUDEPATH += ../src, because the current directory was ./translations.Nonconductor
@Nonconductor thanks. Your comment further helped me solve the build error.Hierodule
F
4

In my case lupdate wasn't able to parse enum MyEnum:int {}; line and failed to reach class declaration. Qt 5.7.1, lupdate still does not understand type specifiers for enums.

Feeling answered 5/1, 2017 at 15:31 Comment(1)
This was the issue for me. Quite annoying. Did you find a workaround?Postbox
H
2

I have seen this error message too using Qt 5.4.1 on an Ubuntu 12.04 system.

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

I'm using something like this in the related 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 worked around by using a 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
Husserl answered 25/7, 2017 at 17:30 Comment(0)
A
2

In my case there was a strangely (but legally I guess) formatted type declaration in a struct before the actual class declaration. This made lupdate skip the class and resulted in the "unqualified" warning message. The code looked like this (wasn't mine to begin with ;-) ):

struct coords_t {
  double x, y;
  ...
};

struct plotsCollection {
  QVarLengthArray<struct coords_t> coords;  // problem right here
  ...
};

class LogsDialog : public QDialog
{
  Q_OBJECT
  ...
}

Removing the struct from QVarLengthArray<struct coords_t> solved the warning. So did moving the struct declarations inside the class. I did both :)

Applique answered 22/12, 2017 at 7:50 Comment(0)
P
1

I just got this same message in a different scenario. In my case, the issue was that foo.cpp contained #include <foo.h> instead #include "foo.h". Since both files were a directory that wasn't in the global include path, lupdate didn't bother looking in that directory due to the lack of quotation marks in the include. Switching to the proper include delimiters made lupdate happy.

Postbox answered 9/5, 2016 at 15:41 Comment(0)
T
0

This error occurs also if the tr()-macro is placed in too deeply nested subfolders.

E.g., in the following example, the command lupdate -noobsolete . -ts ts/* error message reads pwd/a/b/c/c.cpp:5: Qualifying with unknown namespace/class ::C.

QT       += core gui

SOURCES += \
    main.cpp \
    a/a.cpp \
    a/b/b.cpp \
    a/b/c/c.cpp

HEADERS += \
    a/a.h \
    a/b/b.h \
    a/b/c/c.h

TRANSLATIONS += \
    ts/foo.ts

However, as others have already mentioned, the *.ts-file seems to be updated correctly.

Tristichous answered 26/10, 2019 at 19:51 Comment(0)
M
0

Some forward declarations seem to cause this warning too. Removing the 'template class MutexQList' line in this class example solves the issue in my case:

#include "bufferwriter.h"
#include "resampleworker.h"
#include "worker_help.h"

class Buffer;
class Project;

template <class T> class MutexQList;

class WorkerRegistry : public QObject
{
    Q_OBJECT
private:
    static WorkerRegistry *my_instance;

    MutexQList<BufferWriter *>*bw_list;                 ///< Liste mit registrierten BufferWriter Instanzen
    MutexQList<ResampleWorker *>*rw_list;               ///< Liste mit registrierten ResampleWorker Instanzen

public:
    static WorkerRegistry *instance();
    static WorkerRegistry &ref();
    static void destroy();
}
Marciemarcile answered 24/8, 2022 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.