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?

removeTranslator fails?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 819 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.
  • Q Offline
    Q Offline
    QTLeearn
    wrote on 7 May 2020, 18:33 last edited by QTLeearn 5 Sept 2020, 15:45
    #1

    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 P 2 Replies Last reply 9 May 2020, 18:17
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 May 2020, 18:37 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 7 May 2020, 18:48
      0
      • S SGaist
        7 May 2020, 18:37

        Hi,

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

        Q Offline
        Q Offline
        QTLeearn
        wrote on 7 May 2020, 18:48 last edited by QTLeearn 5 Jul 2020, 18:56
        #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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 May 2020, 19:09 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 8 May 2020, 01:16
          0
          • S SGaist
            7 May 2020, 19:09

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

            Q Offline
            Q Offline
            QTLeearn
            wrote on 8 May 2020, 01:16 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
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 8 May 2020, 05:14 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 9 May 2020, 15:42
              2
              • S SGaist
                7 May 2020, 19:09

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

                Q Offline
                Q Offline
                QTLeearn
                wrote on 9 May 2020, 15:41 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
                • C Christian Ehrlicher
                  8 May 2020, 05:14

                  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 9 May 2020, 15:42 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 9 May 2020, 18:06 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
                      7 May 2020, 18:33

                      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 9 May 2020, 18:17 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
                        7 May 2020, 18:33

                        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

                        P Offline
                        P Offline
                        Pablo J. Rogina
                        wrote on 9 May 2020, 22:02 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

                        7/11

                        9 May 2020, 15:41

                        • Login

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