QMessageBox doesn't translate the QString[Solved]



  • @ QInputDialog::getText(this,tr("Open"),tr("New"),QLineEdit::Normal,tr(""),&ok);@

    the translator is loaded and installed but open and new
    don't get translated

    but if i do this :
    @//define Open and New in the mainwindow header file
    QString Open,New;
    //then define a new function
    rename()
    {
    Open=tr("Open");
    New=tr("New");
    }@

    then
    every time i switch the installer i call rename
    @rename();
    QInputDialog::getText(this,Open,New,QLineEdit::Normal,tr(""),&ok);@

    translation works fine



  • Which version of Qt are you using? Do you create instance of QTranslator before the creation of the app's widgets?



  • hi,thanks ,i'm using 5.0.2

    the problem is that i declared QTranslator ,
    load the file and install it inside a function
    so when it exits it destroys the transltor
    so i removed the definition of the translator
    to the constructor then load and install it in the function

    but don't know why it works fine with rename()



  • [quote author="karim24" date="1378697691"]
    the problem is that i declared QTranslator ,
    load the file and install it inside a function
    so when it exits it destroys the transltor
    so i removed the definition of the translator
    to the constructor then load and install it in the function

    but don't know why it works fine with rename()[/quote]

    Check "the documentation of QTranslator":http://qt-project.org/doc/qt-5.0/qtcore/qtranslator.html and have a look at the notes:

    bq. Note that the translator must be created before the application's widgets.

    Btw the documentation also contains useful examples.



  • i solved the problem the thing is before it was like this:

    @void retranslate()
    {
    QTranslator translator;//local variable gets destroyed when exiting
    translator.load(path);
    qApp->installTranslator(&translator);
    }@

    and i solved it by moving the declaration of translator to the constructor
    @QTranslator translator;@

    and modified the retranslate() like this
    @void retranslate()
    {
    translator.load(path);
    qApp->installTranslator(&translator);
    }@



  • Well done :) please add prefix [SOLVED] to the title of the thread.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.