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. removeTranslator fails?
Qt 6.11 is out! See what's new in the release blog

removeTranslator fails?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 1.5k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Might be a silly question but are you sure your translations are loaded successfully as well ?

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

    Q 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Might be a silly question but are you sure your translations are loaded successfully as well ?

      Q Offline
      Q Offline
      QTLeearn
      wrote on last edited by QTLeearn
      #3

      @SGaist Yes, I implemented the following codes to verify:

          successLoad = mTranslator.load("lang_de.qm", mLangDir);
      
          successInstall = qApp->installTranslator(&mTranslator);
      
          qInfo() << "Load trans file successful?" << successLoad;
          qInfo() << "Trans install successful?" << successInstall;
      

      They always printed out true.

      Basically, every time when a qm file is loaded initially, everything is fine. Butwhen I try to switch to another qm file, removeTranslator seems failed, and the corresponding texts don't display properly

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

        Is mTranslator modified at some point in your application ?
        Where is it located ?

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

        Q 2 Replies Last reply
        0
        • SGaistS SGaist

          Is mTranslator modified at some point in your application ?
          Where is it located ?

          Q Offline
          Q Offline
          QTLeearn
          wrote on last edited by
          #5

          @SGaist mTranslator is declared as the private member of this Class, QTranslator mTranslator I don't think it's being changed somewhere else. Thank you

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            You call removeTranslator() twice so the second one will fail. Please check the return value of the first one.

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

            Q 1 Reply Last reply
            2
            • SGaistS SGaist

              Is mTranslator modified at some point in your application ?
              Where is it located ?

              Q Offline
              Q Offline
              QTLeearn
              wrote on last edited by
              #7

              @SGaist Thank you for your help, I resolved this problem myself. If you would like to check the update in my question

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                You call removeTranslator() twice so the second one will fail. Please check the return value of the first one.

                Q Offline
                Q Offline
                QTLeearn
                wrote on last edited by
                #8

                @Christian-Ehrlicher Thank you, I resolved this problem myself

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

                  Haaaaa ! I somehow missed that you were doing that in a QML app...

                  Glad you found out and thanks for sharing !

                  Since you have it working now please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :-)

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

                  1 Reply Last reply
                  0
                  • Q QTLeearn

                    Hi, I am implementing switching multiple translation files (.qm files), I would like to display text contents in qml files in different languages, qstrid-based. I know that before loading a new translation file I should remove the previous translator, so I implemented some codes like:

                    if( ! mTranslator.isEmpty() ) {
                               qApp->removeTranslator(&mTranslator);
                               qInfo() << "Translator is now empty?" << mTranslator.isEmpty();
                               qInfo() << "Translator removal is successful?" << qApp->removeTranslator(&mTranslator);
                    }
                    
                    mTranslator.load("lang_de.qm", mLangDir);
                    qApp->installTranslator(&mTranslator);
                    

                    mTranslator is declared as QTranslator mTranslator;

                    However, removeTranslator always returned false, does that mean the removal failed?
                    Also, after switching different files, translated contents didn't display properly. Did the failure of removal cause this issue? Any ideas on this issue? Thank you very much

                    Update:

                    I resolved the problem my self, the trick part is I should add a Q_PROPERTY emtyString, this is to ensure when the language changes, there's a signal from C++ side to notify the QML to refresh the display contents.
                    A more detailed description can be found here: https://wiki.qt.io/How_to_do_dynamic_translation_in_QML

                    However, removeTranslator still returns false, but this doesn't affect the translation, I am a bit confused

                    B Offline
                    B Offline
                    Bonnie
                    wrote on last edited by
                    #10

                    @QTLeearn

                    However, removeTranslator still returns false, but this doesn't affect the translation, I am a bit confused

                    That's because of what @Christian-Ehrlicher said:

                    You call removeTranslator() twice so the second one will fail. Please check the return value of the first one.

                    1 Reply Last reply
                    0
                    • Q QTLeearn

                      Hi, I am implementing switching multiple translation files (.qm files), I would like to display text contents in qml files in different languages, qstrid-based. I know that before loading a new translation file I should remove the previous translator, so I implemented some codes like:

                      if( ! mTranslator.isEmpty() ) {
                                 qApp->removeTranslator(&mTranslator);
                                 qInfo() << "Translator is now empty?" << mTranslator.isEmpty();
                                 qInfo() << "Translator removal is successful?" << qApp->removeTranslator(&mTranslator);
                      }
                      
                      mTranslator.load("lang_de.qm", mLangDir);
                      qApp->installTranslator(&mTranslator);
                      

                      mTranslator is declared as QTranslator mTranslator;

                      However, removeTranslator always returned false, does that mean the removal failed?
                      Also, after switching different files, translated contents didn't display properly. Did the failure of removal cause this issue? Any ideas on this issue? Thank you very much

                      Update:

                      I resolved the problem my self, the trick part is I should add a Q_PROPERTY emtyString, this is to ensure when the language changes, there's a signal from C++ side to notify the QML to refresh the display contents.
                      A more detailed description can be found here: https://wiki.qt.io/How_to_do_dynamic_translation_in_QML

                      However, removeTranslator still returns false, but this doesn't affect the translation, I am a bit confused

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #11

                      @QTLeearn said in removeTranslator fails?:

                      I resolved the problem my self,

                      Great. Please don't forget to mark your post as solved!

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      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