Hello,
I have created namespaces for my modules in my project so that every sub module lives in its own namespace. Eg for the viewer classes I created the namespace ViewerUI like this in class MainWindow:
#include <QMainWindow>
namespace SubModule1
{
class HelperClass1
}
namespace SubModule2
{
class HelperClass2;
}
namespace ViewerUI
{
{
public:
MainWindow(int argc, char* argv[]);
~MainWindiw();
[...]
void setHelperClass1(const SubModule1::HelperClass1* hc);
[...]
private:
HelperClass1* mHelperClass;
};
}
#include <QMainWindow>
namespace SubModule1
{
class HelperClass1
}
namespace SubModule2
{
class HelperClass2;
}
namespace ViewerUI
{
class MainWindow : public QMainWindow
{
public:
MainWindow(int argc, char* argv[]);
~MainWindiw();
[...]
void setHelperClass1(const SubModule1::HelperClass1* hc);
[...]
private:
HelperClass1* mHelperClass;
};
}
To copy to clipboard, switch view to plain text mode
Using this namespace in cpp file:
#include "MainWindow.h"
namespace ViewerUI
{
using SubModule1::HelperClass1;
MainWindow::MainWindiw(int argc, char* argv[]) : QMainWindiw(argc, argv)
{
[...]
t->load(":/Viewer_de");
installTranslator(translator);
[...]
}
[...]
void setHelperClass1(const SubModule1::HelperClass1* hc)
{
mHelperClass = hc;
QString t
= tr
("Test output should be translated here!");
}
[...]
}
#include "MainWindow.h"
namespace ViewerUI
{
using SubModule1::HelperClass1;
MainWindow::MainWindiw(int argc, char* argv[]) : QMainWindiw(argc, argv)
{
[...]
QTranslator* t = new QTranslator(this);
t->load(":/Viewer_de");
installTranslator(translator);
[...]
}
[...]
void setHelperClass1(const SubModule1::HelperClass1* hc)
{
mHelperClass = hc;
QString t = tr("Test output should be translated here!");
}
[...]
}
To copy to clipboard, switch view to plain text mode
Installing the created translator in constructor of MainWindow class without namespaces results in translation of strings enclosed with tr() macro. But if I use namespaces, strings are no more translated to german.
In assistant docs to QObject there is an issue of so called translation contexts, using Q_OBJECT in a class derived from QObject results in setting the translation context to the name of the subclass? Don't understand this. I want to have translated strings everywhere in the project not just in main window class.
Any hints & help appreciated,
AlGaN
Edit: Ok, not to mind anymore, a new lupdate execution collected the translatable strings in a new translation context containing namespaces and classes. Thanks & Greetiongs 
AlGaN
Bookmarks