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. QTranslator
Forum Updated to NodeBB v4.3 + New Features

QTranslator

Scheduled Pinned Locked Moved General and Desktop
qtranslator
8 Posts 3 Posters 3.0k Views 2 Watching
  • 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.
  • Lays147L Offline
    Lays147L Offline
    Lays147
    wrote on last edited by Lays147
    #1

    Hi guys, a doubt: I'm reading about the qtranslator class and seems to me that i can't switch the language in the execution time, only when the app is not loaded, this is correct?
    On this case when the user switch the language i will need killl and restart my app, correct?
    thanks!

    A 1 Reply Last reply
    0
    • Lays147L Lays147

      Hi guys, a doubt: I'm reading about the qtranslator class and seems to me that i can't switch the language in the execution time, only when the app is not loaded, this is correct?
      On this case when the user switch the language i will need killl and restart my app, correct?
      thanks!

      A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      @Lays147

      Incorrect.

      https://wiki.qt.io/How_to_create_a_multi_language_application

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        No, you can do it at run time. See the documentation here

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Lays147L 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          No, you can do it at run time. See the documentation here

          Lays147L Offline
          Lays147L Offline
          Lays147
          wrote on last edited by
          #4

          @SGaist I'm confused.
          Inside my app the user select the language that hes prefer to use. On the trigger event i need translate my Ui's. But inside my class i dont see how to do it. Because the first translate on my app occurs on main.cpp, and the event that im talking stays inside on my brprint.cpp file. How to do it?
          I'm trying this, but nothing happens.

          void BrPrint3D::on_actionPortuguese_triggered()
          {
              QTranslator trans;
              trans.load(":/Translations/PT_portuguese.qm");
              ui->retranslateUi(this);
          }
          
          1 Reply Last reply
          0
          • A Offline
            A Offline
            alex_malyu
            wrote on last edited by
            #5

            Have you looked at the example I gave a link to?

            To change the language dynamically you to do 2 things:

            1. install translator .
              From the code i referred to:

            void switchTranslator(QTranslator& translator, const QString& filename)
            {
            // remove the old translator
            qApp->removeTranslator(&translator);

            // load the new translator
            if(translator.load(filename))
            qApp->installTranslator(&translator);
            }

            1. Update controls for every widget which needs a translation.
              In the referred code this is done by calling ui.retranslateUi()

            void MainWindow::changeEvent(QEvent* event)
            {
            if(0 != event) {
            switch(event->type()) {
            // this event is send if a translator is loaded
            case QEvent::LanguageChange:
            ui.retranslateUi(this);
            break;

            3

            Lays147L 2 Replies Last reply
            0
            • A alex_malyu

              Have you looked at the example I gave a link to?

              To change the language dynamically you to do 2 things:

              1. install translator .
                From the code i referred to:

              void switchTranslator(QTranslator& translator, const QString& filename)
              {
              // remove the old translator
              qApp->removeTranslator(&translator);

              // load the new translator
              if(translator.load(filename))
              qApp->installTranslator(&translator);
              }

              1. Update controls for every widget which needs a translation.
                In the referred code this is done by calling ui.retranslateUi()

              void MainWindow::changeEvent(QEvent* event)
              {
              if(0 != event) {
              switch(event->type()) {
              // this event is send if a translator is loaded
              case QEvent::LanguageChange:
              ui.retranslateUi(this);
              break;

              3

              Lays147L Offline
              Lays147L Offline
              Lays147
              wrote on last edited by Lays147
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • A alex_malyu

                Have you looked at the example I gave a link to?

                To change the language dynamically you to do 2 things:

                1. install translator .
                  From the code i referred to:

                void switchTranslator(QTranslator& translator, const QString& filename)
                {
                // remove the old translator
                qApp->removeTranslator(&translator);

                // load the new translator
                if(translator.load(filename))
                qApp->installTranslator(&translator);
                }

                1. Update controls for every widget which needs a translation.
                  In the referred code this is done by calling ui.retranslateUi()

                void MainWindow::changeEvent(QEvent* event)
                {
                if(0 != event) {
                switch(event->type()) {
                // this event is send if a translator is loaded
                case QEvent::LanguageChange:
                ui.retranslateUi(this);
                break;

                3

                Lays147L Offline
                Lays147L Offline
                Lays147
                wrote on last edited by
                #7

                @alex_malyu How i can access my qApp on main.cpp starting from my class A? thats my doubt. Because the action to change language is tiggered from my class A. I'm try pass qApp by reference to my class A but the qt dont accept.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alex_malyu
                  wrote on last edited by alex_malyu
                  #8

                  #include <QCoreApplication>

                  .......

                  qApp->

                  Like a global pointer: QApplication* qApp

                  1 Reply Last reply
                  0

                  • Login

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