PDA

View Full Version : lupdate fails to detect context for class in namespace



Infinity
3rd July 2014, 16:48
Hi,

I put all the classes of my application into certain namespaces. Now I wanted to generate ts-files using lupdate.

Generally this works fine, but for some classes the context is not set properly - the namespace is missing.

QtGui::MainWindows is such a class:


#include <QPlainTextEdit>
#include <QWebFrame>
#include <QWebPage>

#include <list>
#include <thread>
#include <sstream>
#include <iomanip>
#include <functional>

using namespace std;
using namespace UtilityFeatures;
using namespace Media;

namespace QtGui {

/*
TRANSLATOR QtGui::MainWindow
Necessary for lupdate.
*/

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent, Qt::Window),
// .....

Because the context can not be detected I added a translator comment before the first definition as you can see. This doesn't help.

For some other classes the namespace detection works fine:


// .....
#include <QScriptEngine>
#include <QScriptProgram>

using namespace std;

namespace RenamingUtility {

/*
TRANSLATOR RenamingUtility::RemamingEngine
Necessary for lupdate.
*/

RemamingEngine::RemamingEngine(QObject *parent) :
QObject(parent),
// ....

As you can see I added here a translator comment as well. But it seems to be unnecessary since the namespace can be detected without as well. Nevertheless the comment gets noticed as hint in Qt Assistant.

There is no difference between these two classes/namespaces except one: The QtGui namespace is also populated by Ui classes generated from ui-files.


<class>QtGui::MainWindow</class>
<widget class="QMainWindow" name="QtGui::MainWindow">

The context for the "designer strings" of the MainWindow class is correctly.

Consequently I'm getting the context "QtGui::MainWindow" in my ts-files which contains all "designer strings" and a context "MainWindow" which contains regular strings wrapped using tr(). Strangely the context "QtGui::MainWindow" also contains the translator comment I added for QtGui::MainWindow in mainwindow.cpp as last "entry".

This seems to be the source of the problem, but I don't know how to fix it. I'm hoping someone can help here. Maybe I've discovered a bug of lupdate here and there is a simple workaround possible.

EDIT: I forgot to post the message lupdate prints for classes like QtGui::MainWindow:

......./gui/mainwindow.cpp:214: Qualifying with unknown namespace/class ::MainWindow

EDIT 2: Solved it.
I figured out that the fact that the QtGui namespace is also populated by Ui classes doesn't cause the problem.
The problem is cause somewhere else: The forward declaration of an enum. This is possible when the base type is specified.


enum class MyEnum : int;

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf

Unfortunately lupdate can not handle this synatax. I walk around that problem using a macro:


#define DECLARE_ENUM(name, base) enum class name : base;
DECLARE_ENUM(MyEnum, int)

It works but looks very ugly. Maybe I'd rather include the header.