Important: Please read the Qt Code of Conduct -

[SOLVED] QTranslator not working?

  • Hi guys,

    I'm trying out the translator system in QT for the first time.
    I fallowed the guide :

    -First genereted the .ts file
    -Edited the .ts file with Qt Linguist (completed the translation 100%)
    -Compiled the .ts file into .qm file in QtCreator

    The .qm file and .ts file are in the root on my project, here's a screenshot:

    I specify in my main to load a specific .ts file just for testing, but it still show the english text. (see code below)
    Anything I forgot to do?
    Thanks in advance /Merci à l'avance :)

    @int main(int argc, char *argv[]) {

    QApplication a(argc, argv);
    QString locale = QLocale::system().name();
    qDebug() << "LOCALE : " << locale;
    QTranslator translator;
    MainWindow w;;
    return a.exec(&#41;;


  • Lifetime Qt Champion


    Without the rest of your code, it's difficult to say what could be wrong. The first guess is: did you surround all your visible texts with tr() ?

  • I set the text directly in QtCreator interface

    An example of generated code looks like this :
    @groupBox->setTitle(QApplication::translate("MainWindow", "Filter", 0));@

    I think it's good syntax cause the generated .ts file make an entry for it


  • Hmm probably a problem with the path of the file

    the boolean return false when I load the file

    @ QTranslator translator;

    bool test = translator.load("powervelo_fr");
    qDebug() << "LOADED? " << test;
    //return false

  • Lifetime Qt Champion

    Are you sure your file is in the same folder as your executable ?

  • Include in your pro file:
    TRANSLATIONS = HD120_en.ts
    Of at least the ts files you need. That's needed for QtLinguist. Also check if your using a shadow build that your files are in the same as the executable file! Not in your project, but in your debug/release folders!!

  • That was the problem, the files were in the project instead of the release/debug folder

    Thanks guys!

  • If that fixed it, place [SOLVED] in front of your first post!!

Log in to reply