Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translation at runtime (dynamic translation)
Forum Update on Monday, May 27th 2025

Translation at runtime (dynamic translation)

Scheduled Pinned Locked Moved Solved General and Desktop
translation
4 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlaaM
    wrote on 4 Jan 2016, 09:33 last edited by AlaaM 1 Apr 2016, 09:34
    #1

    I have a screen to pick the language for the app.
    I understand that I need to call app.removeTranslator() and then app.installTranslator(); on the language switch, and then listen to QEvent::LanguageChange to retranslate.
    But the problem is I don't have access to app in that screen:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv); //app is declared here
    
        QTranslator translator;
        translator.load("myApp_en");
        app.installTranslator(&translator);
    
        LoadingScreen loadingScreen;
        loadingScreen.showWindow();
    
        return app.exec();
    }
    

    And I need to change the language from another class, which inherits from QMainWindow. All widgets are created dynamically in code. For example:

    title = new QLabel();
    title->setText(tr("Choose Language"));
    

    So can someone tell me please how can I install a new translator from this other class?

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 4 Jan 2016, 09:35 last edited by
      #2

      hi
      there is qApp that works in all application.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        AlaaM
        wrote on 4 Jan 2016, 09:48 last edited by AlaaM 1 Apr 2016, 09:48
        #3

        @mrjj Oh! Life saver!
        Do I really have to removeTranslator before installing a new one though?

        M 1 Reply Last reply 4 Jan 2016, 10:01
        0
        • A AlaaM
          4 Jan 2016, 09:48

          @mrjj Oh! Life saver!
          Do I really have to removeTranslator before installing a new one though?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 4 Jan 2016, 10:01 last edited by
          #4

          @AlaaM ¨
          Hi I think you can have multiple translators(file) active, so when you switch language
          its best to remove old one or it might get messy as the old one would also be searched.
          But if completely different language, i doubt anything crazy will happen.

          http://www.informit.com/articles/article.aspx?p=1405555&seqNum=3

          1 Reply Last reply
          1

          3/4

          4 Jan 2016, 09:48

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved