Results 1 to 5 of 5

Thread: lupdate problem

  1. #1
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default lupdate problem

    Hi,

    I have encountered problem with lupdate. It is not able to add few strings to translation file.
    Simplified code sample is showed below.

    TrProblem.pro
    Qt Code:
    1. TARGET = TrProblem
    2. TEMPLATE = app
    3.  
    4. TRANSLATIONS = TrProblem_de.ts
    5.  
    6. DEFINES += EV_SOURCE
    7.  
    8. SOURCES += main.cpp\
    9. mainwindow.cpp
    10.  
    11. HEADERS += mainwindow.h \
    12. ../common/defs.h
    13.  
    14. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    defs.h
    Qt Code:
    1. #ifndef _DEFS_H_
    2. #define _DEFS_H_
    3.  
    4. enum some_enum_t
    5. {
    6. SOME_VALUE_0 = 0,
    7. SOME_VALUE_1,
    8. SOME_VALUE_2,
    9. SOME_VALUE_3
    10. };
    11.  
    12. #ifdef EV_SOURCE
    13.  
    14. #include <QCoreApplication>
    15.  
    16. class CommonStr
    17. {
    18. Q_DECLARE_TR_FUNCTIONS(CommonStr)
    19.  
    20. public:
    21. static CommonStr& Acquire() { static CommonStr str; return str; }
    22.  
    23. QString to_str(some_enum_t pt);
    24.  
    25. private:
    26. CommonStr() {};
    27. };
    28.  
    29.  
    30. #define RETURN_TYPE QString
    31. #define ACCESS_OBJECT
    32. #define TR(STRING) tr(STRING)
    33.  
    34. #else
    35.  
    36. #define ACCESS_OBJECT
    37. #define RETURN_TYPE char const *
    38. #define TR(STRING) STRING
    39.  
    40. #endif
    41.  
    42. inline RETURN_TYPE ACCESS_OBJECT to_str(product_t pt)
    43. {
    44. switch(pt)
    45. {
    46. case SOME_VALUE_0: return TR("SOME_VALUE_0");
    47. case SOME_VALUE_1: return TR("SOME_VALUE_1");
    48. case SOME_VALUE_2: return TR("SOME_VALUE_2");
    49. case SOME_VALUE_3: return TR("SOME_VALUE_3");
    50. default: return TR("UNKNOWN_VALUE");
    51. }
    52. }
    53.  
    54.  
    55.  
    56. #endif
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp - CommomStr usage
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include "defs.h"
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. QString str = CommonStr::Acquire().to_str(SOME_VALUE_1);
    12. str;
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    To copy to clipboard, switch view to plain text mode 


    After running command "lupdate -verbose TrProblem.pro" i receive such output:
    /usr/include/qt4/QtCore/qstringbuilder.h:45: circular inclusion of /usr/include/qt4/QtCore/qstring.h

    /usr/include/qt4/QtGui/qwmatrix.h:45: circular inclusion of /usr/include/qt4/QtGui/qmatrix.h

    /usr/include/qt4/QtGui/qactiongroup.h:45: circular inclusion of /usr/include/qt4/QtGui/qaction.h

    /home/kuba/Develop/translation_problem/common/defs.h:46: tr() cannot be called without context

    /home/kuba/Develop/translation_problem/common/defs.h:47: tr() cannot be called without context

    /home/kuba/Develop/translation_problem/common/defs.h:48: tr() cannot be called without context

    /home/kuba/Develop/translation_problem/common/defs.h:49: tr() cannot be called without context

    /home/kuba/Develop/translation_problem/common/defs.h:50: tr() cannot be called without context

    Updating 'TrProblem_de.ts'...
    Found 1 source text(s) (0 new and 1 already existing)
    Is there any problem with such macro definitions for lupdate? I know that tr() function does not work with #defines but if it expands defs.h correctly it should work in my opinion.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: lupdate problem

    tr() is a method of QObject, to_str() doesn't appear to be a method of a QObject subclass so it would have to use QObject::tr()

    Also I don't think lupdate will see the strings, it looks for tr() and translate(), case sensitive as far as I remember.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: lupdate problem

    Yes you are right tr() is method from QObject, but macro Q_DECLARE_TR_FUNCTIONS adds this method to my class. I have tried also to subclass CommomStr class from QObject but i without any success. Result is the same.
    I have suspiction that there is something wrong with preprocessor directives in defs.h. I mean they are all right but lupdate can't handle then properly.
    And TR is only preprocessor directive. In Qt project it is expanded to tr().

    Thanks for fast reply

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: lupdate problem

    You define to_str as a standalone function and not a class member (despite earlier declaration of such method). As for TR vs tr, lupdate runs directly on your file, without passing it to through the preprocessor so it will not see your TR alias and will fail to extract those strings.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: lupdate problem

    Thanks. This was my suspicion.

Similar Threads

  1. lupdate errors?
    By nthung in forum Newbie
    Replies: 3
    Last Post: 13th October 2011, 13:17
  2. lupdate.exe problem on Windows 7 (Qt 4.6.2)
    By glimberg in forum Installation and Deployment
    Replies: 0
    Last Post: 2nd April 2010, 21:29
  3. Problem with lupdate
    By loris128 in forum Qt Tools
    Replies: 3
    Last Post: 8th April 2009, 20:36
  4. 4.2 and lupdate
    By Byngl in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 03:55
  5. lupdate *.pro troubles
    By jeff_s in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2006, 10:07

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.