views:

39

answers:

1

Hi,

i want to load the localized string in Qt application. for this i am following few steps, correct me if i am wrong.

Note: it works fine for QString but not for const char*

1)update the pro file with translation language 2)generate .ts & edit using Qt linguist. Generate .qm file using lupdate and lrelease. 3)load the .qm file from particular location.

here is how my const char* looks.

const char* sayHellow =  QT_TRANSLATE_NOOP("FriendlyConversation","hellow");

LocalizationWithQT::LocalizationWithQT(QWidget *parent)
    : QMainWindow(parent)
{
 //ui.setupUi(this);
 QString str = tr("say hellow");
 QPushButton *pushbutton = new QPushButton(tr(sayHellow));
 setCentralWidget(pushbutton);

}

here how i am loading the .qm file

QApplication a(argc, argv);

    QTranslator translator;
    bool val = translator.load("c:\\Data\\test\\hellotr_la");
    a.installTranslator(&translator);

    LocalizationWithQT w;
    w.showMaximized();
    return a.exec();

the problem is, if i provide any alternate Latin string to "sayhellow" its not loading at all.. i don't no where is the mistake.. please suggest me the solution..

Thanks in advance

A: 

If you use tr(sayHellow), Qt will look for the sayHellow translation in the current context (=LocalizationWithQT class).

You must give Qt the text context explicitly:

QPushButton *pushbutton 
    = new QPushButton(qApp->translate("FriendlyConversation", sayHellow));
TimW