Results 1 to 1 of 1

Thread: [solved] Translation context vs namespaces

  1. #1
    Join Date
    May 2006
    Location
    Stuttgart, Germany
    Posts
    22
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [solved] Translation context vs namespaces

    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:

    Qt Code:
    1. #include <QMainWindow>
    2.  
    3. namespace SubModule1
    4. {
    5. class HelperClass1
    6. }
    7. namespace SubModule2
    8. {
    9. class HelperClass2;
    10. }
    11.  
    12. namespace ViewerUI
    13. {
    14. class MainWindow : public QMainWindow
    15. {
    16. public:
    17. MainWindow(int argc, char* argv[]);
    18.  
    19. ~MainWindiw();
    20.  
    21. [...]
    22.  
    23. void setHelperClass1(const SubModule1::HelperClass1* hc);
    24.  
    25. [...]
    26. private:
    27. HelperClass1* mHelperClass;
    28. };
    29. }
    To copy to clipboard, switch view to plain text mode 

    Using this namespace in cpp file:
    Qt Code:
    1. #include "MainWindow.h"
    2.  
    3. namespace ViewerUI
    4. {
    5. using SubModule1::HelperClass1;
    6.  
    7. MainWindow::MainWindiw(int argc, char* argv[]) : QMainWindiw(argc, argv)
    8. {
    9. [...]
    10. QTranslator* t = new QTranslator(this);
    11. t->load(":/Viewer_de");
    12. installTranslator(translator);
    13. [...]
    14. }
    15.  
    16. [...]
    17. void setHelperClass1(const SubModule1::HelperClass1* hc)
    18. {
    19. mHelperClass = hc;
    20. QString t = tr("Test output should be translated here!");
    21. }
    22. [...]
    23. }
    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
    Last edited by AlGaN; 21st January 2010 at 09:18.

Similar Threads

  1. Q_DECLARE_INTERFACE and namespaces
    By JPNaude in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2011, 15:39
  2. ui headers and namespaces
    By Rockem in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2009, 18:47
  3. XML Namespaces
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2008, 09:00
  4. namespaces and translations
    By gri in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2007, 09:53
  5. problem with namespaces
    By steve918 in forum General Programming
    Replies: 1
    Last Post: 17th September 2006, 16:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.