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. retranslateUi method freezing application - Multi language support

retranslateUi method freezing application - Multi language support

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.7k Views 3 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.
  • M Offline
    M Offline
    masa4
    wrote on last edited by
    #1

    I added second language to my program with advices from: https://forum.qt.io/topic/143541/proper-way-for-adding-2nd-language

    I have a combobox for language selection. When I change language in combobox, the programs' language changing without problem on my computer.

    But when i tried on another computer, the program freezes. I tried debugging but no chance, because program is not crashing, just freezing.

    I have this on my settings page:

    // t is a QTranslator object
    void Settings::on_comboBoxLanguage_currentIndexChanged(int index)
    {
        if(index == 0){
            t.load(":/i18n/lang_en.qm");
            db->updateLanguage("English");
        }
        else if(index == 1){
            t.load(":/i18n/lang_it.qm");
            db->updateLanguage("Italian");
        }
    
        QCoreApplication::installTranslator(&t);
        Q_EMIT RetranslateUI();
    }
    

    And I have this on other ui classes:

    void MainPage::RetranslateUISlot()
    {
        ui->retranslateUi(this);
    }
    

    Both computers are Linux but different distros. I dont know how to debug it. Any idea?

    Christian EhrlicherC 1 Reply Last reply
    0
    • M masa4

      I added second language to my program with advices from: https://forum.qt.io/topic/143541/proper-way-for-adding-2nd-language

      I have a combobox for language selection. When I change language in combobox, the programs' language changing without problem on my computer.

      But when i tried on another computer, the program freezes. I tried debugging but no chance, because program is not crashing, just freezing.

      I have this on my settings page:

      // t is a QTranslator object
      void Settings::on_comboBoxLanguage_currentIndexChanged(int index)
      {
          if(index == 0){
              t.load(":/i18n/lang_en.qm");
              db->updateLanguage("English");
          }
          else if(index == 1){
              t.load(":/i18n/lang_it.qm");
              db->updateLanguage("Italian");
          }
      
          QCoreApplication::installTranslator(&t);
          Q_EMIT RetranslateUI();
      }
      

      And I have this on other ui classes:

      void MainPage::RetranslateUISlot()
      {
          ui->retranslateUi(this);
      }
      

      Both computers are Linux but different distros. I dont know how to debug it. Any idea?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @masa4 said in retranslateUi method freezing application - Multi language support:

      . I tried debugging but no chance, because program is not crashing, just freezing.

      And what was the result - what do you see in the backtrace where your program hangs?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @masa4 said in retranslateUi method freezing application - Multi language support:

        . I tried debugging but no chance, because program is not crashing, just freezing.

        And what was the result - what do you see in the backtrace where your program hangs?

        M Offline
        M Offline
        masa4
        wrote on last edited by
        #3

        @Christian-Ehrlicher When I stop debugging, there is lots of line that dont make much sense to me. But it is like the RetranslateUI signal keep emitting continuosly. I dont know

        J.HilkJ 1 Reply Last reply
        0
        • M masa4

          @Christian-Ehrlicher When I stop debugging, there is lots of line that dont make much sense to me. But it is like the RetranslateUI signal keep emitting continuosly. I dont know

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @masa4 do you retranslate/recreate your combobox model ?

          It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Christian EhrlicherC M 2 Replies Last reply
          0
          • J.HilkJ J.Hilk

            @masa4 do you retranslate/recreate your combobox model ?

            It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @J-Hilk said in retranslateUi method freezing application - Multi language support:

            It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

            That's also my idea and therefore the hint to look at the backtrace but as always I'm getting ignored :)

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            J.HilkJ 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @J-Hilk said in retranslateUi method freezing application - Multi language support:

              It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

              That's also my idea and therefore the hint to look at the backtrace but as always I'm getting ignored :)

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Christian-Ehrlicher thats normal :D

              the strange thing is still that is happens on one pc and not on the other, the behaviour should be the same in both cases, right?


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              Christian EhrlicherC 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @Christian-Ehrlicher thats normal :D

                the strange thing is still that is happens on one pc and not on the other, the behaviour should be the same in both cases, right?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @J-Hilk said in retranslateUi method freezing application - Multi language support:

                the behaviour should be the same in both cases

                Yes, but maybe there is a QueuedConnection somewhere which affects the timing. Need to see the backtrace (or more than one at different times when they really differ)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @masa4 do you retranslate/recreate your combobox model ?

                  It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

                  M Offline
                  M Offline
                  masa4
                  wrote on last edited by
                  #8

                  @J-Hilk No I dont change anything about combobox.I have retranslateuiSlot in Settings.cpp too. I am retranslating setting ui. In my combo box i have 2 items for both language. By the way my computer uses qt 6.x and other one uses 5.x .

                  J.HilkJ 1 Reply Last reply
                  0
                  • M masa4

                    @J-Hilk No I dont change anything about combobox.I have retranslateuiSlot in Settings.cpp too. I am retranslating setting ui. In my combo box i have 2 items for both language. By the way my computer uses qt 6.x and other one uses 5.x .

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @masa4 said in retranslateUi method freezing application - Multi language support:

                    qt 6.x and other one uses 5.x .

                    how does that work? Did you compile it for Qt5 and for Qt6. Or do you simply run the Qt5 version with Qt6 libraries and it accidentally worked ?


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    M 1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @masa4 said in retranslateUi method freezing application - Multi language support:

                      qt 6.x and other one uses 5.x .

                      how does that work? Did you compile it for Qt5 and for Qt6. Or do you simply run the Qt5 version with Qt6 libraries and it accidentally worked ?

                      M Offline
                      M Offline
                      masa4
                      wrote on last edited by masa4
                      #10

                      @J-Hilk No i recompiled project on other pc with qt5 libraries. I always do like that without any problem. If i am not wrong the language changing mechanism was working without any issue. But after it, i add several other things to my program and now i got that problem.

                      For example I added a label to one of my ui's. I didnt create a translation for that label yet. Can it be cause the problem?

                      Additionally,
                      I have this in Settings.cpp constructor:

                      if(db->selectLanguage()=="English"){
                              ui->comboBoxLanguage->setCurrentIndex(0);
                              t.load(":/i18n/lang_en.qm");
                          }
                          else if(db->selectLanguage()=="Italian"){
                              ui->comboBoxLanguage->setCurrentIndex(1);
                              t.load(":/i18n/lang_it.qm");
                          }
                      
                          QCoreApplication::installTranslator(&t);
                          Q_EMIT RetranslateUI();
                      

                      When program starts, I am creating a settins object in mainwidget so this constructors run and im reading the language from databse and setting the ui language according to db.

                      SGaistS 1 Reply Last reply
                      0
                      • M masa4

                        @J-Hilk No i recompiled project on other pc with qt5 libraries. I always do like that without any problem. If i am not wrong the language changing mechanism was working without any issue. But after it, i add several other things to my program and now i got that problem.

                        For example I added a label to one of my ui's. I didnt create a translation for that label yet. Can it be cause the problem?

                        Additionally,
                        I have this in Settings.cpp constructor:

                        if(db->selectLanguage()=="English"){
                                ui->comboBoxLanguage->setCurrentIndex(0);
                                t.load(":/i18n/lang_en.qm");
                            }
                            else if(db->selectLanguage()=="Italian"){
                                ui->comboBoxLanguage->setCurrentIndex(1);
                                t.load(":/i18n/lang_it.qm");
                            }
                        
                            QCoreApplication::installTranslator(&t);
                            Q_EMIT RetranslateUI();
                        

                        When program starts, I am creating a settins object in mainwidget so this constructors run and im reading the language from databse and setting the ui language according to db.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @masa4 Hi,

                        There's no need for such a signal:

                        void MyWidget::changeEvent(QEvent *event)
                        {
                            if (event->type() == QEvent::LanguageChange) {
                                titleLabel->setText(tr("Document Title"));
                                ...
                                okPushButton->setText(tr("&OK"));
                            } else
                                QWidget::changeEvent(event);
                        }
                        

                        See the internationalization documentation for more.

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

                        M 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          @masa4 Hi,

                          There's no need for such a signal:

                          void MyWidget::changeEvent(QEvent *event)
                          {
                              if (event->type() == QEvent::LanguageChange) {
                                  titleLabel->setText(tr("Document Title"));
                                  ...
                                  okPushButton->setText(tr("&OK"));
                              } else
                                  QWidget::changeEvent(event);
                          }
                          

                          See the internationalization documentation for more.

                          M Offline
                          M Offline
                          masa4
                          wrote on last edited by
                          #12

                          @SGaist I will check it out, thanks.

                          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