Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQmlEngine.retranslate() blocks main thread
Forum Updated to NodeBB v4.3 + New Features

QQmlEngine.retranslate() blocks main thread

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 1.1k 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.
  • W Offline
    W Offline
    Witzgy
    wrote on last edited by
    #1

    Hello,
    in the QML-project at hand running on an embedded device the transition from one language to another language takes 4 seconds. It seems that the engine's retranslate() slot blocks the main thread during this period.
    A busy-indicator-animation would be desired. But since the engine handles both visual components and language binding refreshing I don't see how the retranslate() work could be outsourced to a separate thread.

    Any ideas are highly appreciated.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to the forums.
      For 4 seconds, could you not just use
      https://doc.qt.io/qt-5/qml-qtquick-controls2-overlay.html#details
      with a nonanimated Wait icon and modal popup so it dimms, and that should be clear to the user it's still processing his/hers language selection?

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Witzgy
        wrote on last edited by
        #3

        Thanks for the welcome.

        The dimming and static icon approach is implemented so far.
        However an animation would be desired...

        mrjjM 1 Reply Last reply
        0
        • W Witzgy

          Thanks for the welcome.

          The dimming and static icon approach is implemented so far.
          However an animation would be desired...

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Witzgy
          Hi
          Ok. It was just a suggestion.
          Wait a bit and maybe some of the other users might have an idea to play animation while
          the main thread is busy. Im not deep enough into QML to know if
          we can refresh the bindings from other threads than the render thread.

          1 Reply Last reply
          0
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by jeremy_k
            #5

            Has an Animator been tried?

            Animator types are a special type of animation which operate directly on Qt Quick's scene graph, rather than the QML objects and their properties like regular Animation types do. This has the benefit that Animator based animations can animate on the scene graph's rendering thread even when the UI thread is blocked.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            2
            • W Offline
              W Offline
              Witzgy
              wrote on last edited by Witzgy
              #6

              @jeremy_k
              Indeed, an Animator would work.
              However, the forseen animation uses a repeating Timer which triggers color changes at various locations.

              jeremy_kJ 1 Reply Last reply
              0
              • W Witzgy

                @jeremy_k
                Indeed, an Animator would work.
                However, the forseen animation uses a repeating Timer which triggers color changes at various locations.

                jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by jeremy_k
                #7

                @Witzgy said in QQmlEngine.retranslate() blocks main thread:

                @jeremy_k
                Indeed, an Animator would work.
                However, the forseen animation uses a repeating Timer which triggers color changes at various locations.

                That reminds me that retranslate() reevaluates all bindings, not just those that involve translated strings. If there are binding heavy items that can be destroyed and recreated at a later time, that should speed up the process. If items can't be completely destroyed, simplifying the bindings could help.

                Asking a question about code? http://eel.is/iso-c++/testcase/

                J.HilkJ 1 Reply Last reply
                1
                • jeremy_kJ jeremy_k

                  @Witzgy said in QQmlEngine.retranslate() blocks main thread:

                  @jeremy_k
                  Indeed, an Animator would work.
                  However, the forseen animation uses a repeating Timer which triggers color changes at various locations.

                  That reminds me that retranslate() reevaluates all bindings, not just those that involve translated strings. If there are binding heavy items that can be destroyed and recreated at a later time, that should speed up the process. If items can't be completely destroyed, simplifying the bindings could help.

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @jeremy_k you're right,

                  @Witzgy you may get a much faster translation happening when you do the old way of translating / updating translatable strings, with the empty string update:
                  https://wiki.qt.io/How_to_do_dynamic_translation_in_QML

                  also, it would probably help if you do not load all QML components on startup.
                  Dynamically created pages/components fetch the correct language string automatically, and you only need to update those, that are currently created.

                  Thats why I have a StackView as root component, where I keep the stack size to a minimum (always pop before push)


                  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.

                  1 Reply Last reply
                  1

                  • Login

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