Qt Localizing Windows

  • My project folder is currently setup like this:
    ---[source files]

    My .pro file:

    Project created by QtCreator 2014-03-18T15:15:40


    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = TestApp
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    In my main.cpp I try to force the translation to JP:
    #include "mainwindow.h"
    #include <QApplication>
    #include <QTranslator>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    QTranslator translator;
    MainWindow w;

    return a.exec(&#41;;


    But the main window still appears in English. Maybe I'm misunderstanding the documentation, but how do we force a certain local for the application?

  • Lifetime Qt Champion


    Are you sure your translation are loaded properly ? If I see things correctly, all your translation files are within your project sources. You application is run from the build directory so it can't find them. So you can either copy the files besides your executable, give the path where to find them to QTranslator or use the resource system.

    Hope it helps

  • Look at this project
    and download it. The it - en translations work very well. You can also embed in the exe the localizations file.

  • I've created a resource file entry for each one of my .qm files then added the resource to the projet. At the start up I load the resource and the path provided is:
    and it works well I guess I needed to put in a full path to .qm file if I wasn't using resource file, but this way seems much simpler

  • Lifetime Qt Champion

    Indeed, that's a catch many people fall in currently, the source tree is not the build tree so using relative path will never have the expected effect

Log in to reply

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