tr with #define..it can work?
Hello, im my default.h i put:
Code:
#define aString "aString";
if i want to use aString as a QString in my project i used to do in this way
but if i want internazionalizzate it with "tr()" function what should i do?
i tried with tr
but i get this error
Code:
main.
cpp:4396: error
: no matching function
for call to ‘main
::tr(QString)’
thx
Re: tr with #define..it can work?
The tr signature is QObject::tr ( const char * sourceText, const char * comment = 0, int n = -1 ) .
So you can just pass aString:
Re: tr with #define..it can work?
good, now i don't get any error...but i did
lupdate project.pro
lrelease project.pro
i can't find the voice in my .ts file...
Re: tr with #define..it can work?
From http://doc.trolltech.com/4.3/i18n.ht...l-literal-text:
Quote:
If you need to have translatable text completely outside a function, there are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP(). They merely mark the text for extraction by the lupdate utility described below. The macros expand to just the text (without the context).
Re: tr with #define..it can work?
Why don't you do it this way ?
Code:
const QString astring
= QObject::tr("astring");
// global or wrapped in singleton class
Re: tr with #define..it can work?
Quote:
Originally Posted by
Gopala Krishna
Why don't you do it this way ?
Code:
const QString astring
= QObject::tr("astring");
// global or wrapped in singleton class
in this way i get a error
Code:
error
: ‘
QString’ does not name a type
Re: tr with #define..it can work?
Quote:
Originally Posted by
mattia
in this way i get a error
Code:
error
: ‘
QString’ does not name a type
Did you include <QString>?
Btw, bender86 already pointed out the correct way to do it if you insist using defines.
Re: tr with #define..it can work?
Hi, i did as bender86 suggest, i added in my default.h this:
Code:
static const char *greeting_string = QT_TR_NOOP("Hellooooo");
and in my*ts file i translated greeting_string,
Code:
<message>
<location filename="../default.h" line="47"/>
<source>Hellooooo</source>
<translation>Ciaooooooooooooooo</translation>
</message>
but when i call tr(greeting_string) in my application i'm not able to see greeting_string translated...I can just read "Hellooooo".
With other QString in my application i I have not problem to see them translated.
Any hint?
thx
Re: tr with #define..it can work?
You must use QT_TRANSLATE_NOOP() outside class context. QT_TR_NOOP() is used inside class context.
Re: tr with #define..it can work?
thanks so much now it correctly works, but when i compile my application i keep having this annoying massage:
Code:
default.h:48: warning: ‘greeting_string’ defined but not used
greeting_string is declared in this wy:
Code:
static const char *greeting_string = QT_TRANSLATE_NOOP( "mainWindow" , "Hello" );
and it's used in mainWindow.
thx