PDA

View Full Version : lupdate problem



cejot
3rd September 2013, 14:01
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


TARGET = TrProblem
TEMPLATE = app

TRANSLATIONS = TrProblem_de.ts

DEFINES += EV_SOURCE

SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h \
../common/defs.h

FORMS += mainwindow.ui


defs.h


#ifndef _DEFS_H_
#define _DEFS_H_

enum some_enum_t
{
SOME_VALUE_0 = 0,
SOME_VALUE_1,
SOME_VALUE_2,
SOME_VALUE_3
};

#ifdef EV_SOURCE

#include <QCoreApplication>

class CommonStr
{
Q_DECLARE_TR_FUNCTIONS(CommonStr)

public:
static CommonStr& Acquire() { static CommonStr str; return str; }

QString to_str(some_enum_t pt);

private:
CommonStr() {};
};


#define RETURN_TYPE QString
#define ACCESS_OBJECT
#define TR(STRING) tr(STRING)

#else

#define ACCESS_OBJECT
#define RETURN_TYPE char const *
#define TR(STRING) STRING

#endif

inline RETURN_TYPE ACCESS_OBJECT to_str(product_t pt)
{
switch(pt)
{
case SOME_VALUE_0: return TR("SOME_VALUE_0");
case SOME_VALUE_1: return TR("SOME_VALUE_1");
case SOME_VALUE_2: return TR("SOME_VALUE_2");
case SOME_VALUE_3: return TR("SOME_VALUE_3");
default: return TR("UNKNOWN_VALUE");
}
}



#endif


mainwindow.cpp - CommomStr usage


#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "defs.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString str = CommonStr::Acquire().to_str(SOME_VALUE_1);
str;
}

MainWindow::~MainWindow()
{
delete ui;
}



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.

anda_skoa
3rd September 2013, 14:52
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,
_

cejot
3rd September 2013, 14:58
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

wysota
4th September 2013, 10:02
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.

cejot
4th September 2013, 11:14
Thanks. This was my suspicion.