Important: Please read the Qt Code of Conduct -

Switch back to native language after install qm file by QTranslator

  • I would like to switch back to native language after translation are done, but can't find a way to do it.

    #include <QApplication>
    #include <QDebug>
    #include <QPushButton>
    #include <QTranslator>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QTranslator translator;
        QPushButton hello(QPushButton::tr("Hello world!"));
        hello.resize(100, 30);
        QTranslator default_language;  
        QObject::connect(&hello, &QPushButton::clicked, [&]()
            static int removed = false;
                qDebug()<<"translator reinstall";
                removed = false;
                qDebug()<<"translator removed";
                removed = QCoreApplication::removeTranslator(&translator);
               //with or without this line, the result is same, the language never convert back to english
        return app.exec();

    What is the proper way to do it?Thanks

  • Moderators

Log in to reply