Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQmlEngine.retranslate() blocks main thread



  • 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.


  • Lifetime Qt Champion

    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?



  • Thanks for the welcome.

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


  • Lifetime Qt Champion

    @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.



  • 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.



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



  • @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.


  • Moderators

    @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)


Log in to reply