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. Dynamically created Qt Quick QML component strings not translated
Forum Update on Monday, May 27th 2025

Dynamically created Qt Quick QML component strings not translated

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 974 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.
  • J Offline
    J Offline
    JDGXNV
    wrote on last edited by
    #1

    We have a top-level QML object inside a QWidget. For the high-level object we call installTranslatorFunctions and the application's current translators are installed appropriately. The QML strings are properly translated.

    However, from our top-level QML object we call Qt.createComponent followed by component.createObject call to show a pure QML dialog. Our problem is the strings in the dynamically created dialog are not being translated appropriately. The same strings that are shared in the top-level QML (from where createComponent is called) are being translated and displayed properly. So we do not suspect that this is a more global issue of not going through the translation process correctly. Is there are separate step that needs to be done to install a translator for this dynamic component? I couldn't find reference to that in my searches.

    We are using Qt 5.4.1.

    Thank you for any assistance or thoughts anyone may provide!

    var component = Qt.createComponent("EditServerDialog.qml")
    var dialog = component.createObject(root, {visible: true, currentIndex: -1})
    

    Where EditServerDialog.qml is (edited for brevity):

    import QtQuick 2.4
    import QtQuick.Window 2.0
    
    import "qrc:/QML/GUI/QML"
    
    Window {
        id: editServerDialogWindow
        width: 600
        height: 350
        flags: Qt.Dialog
        modality: Qt.ApplicationModal
    
    
        EditServerDialogForm {
       }
    }
    

    and EditServerDialogForm was created in QML Designer:

    import QtQuick 2.4
    import QtQuick.Controls 1.2
    
    Item {
        id: editServerUiContent
        clip: false
        width: 600
        height: 350
        transformOrigin: Item.Center
        
        Label {
            id: label1
            x: 39
            y: 41
            text: qsTr("Connection Name")
            verticalAlignment: Text.AlignVCenter
        }
    
        Label {
            id: label2
            x: 116
            y: 81
            text: qsTr("Server")
        }
    
        Label {
            id: label3
            x: 121
            y: 121
            text: qsTr("Share")
        }
    
        Label {
            id: label4
            x: 108
            y: 161
            text: qsTr("Domain")
        }
    
        Label {
            id: label5
            x: 92
            y: 201
            text: qsTr("Username")
        }
    
        Label {
            id: label6
            x: 95
            y: 241
            text: qsTr("Password")
        }
    
        property alias cancelButton: buttonCancel
        Button {
            id: buttonCancel
            x: 479
            y: 293
            text: qsTr("Cancel")
            isDefault: true
        }
    
        property alias okButton: buttonOk
        Button {
            id: buttonOk
            x: 380
            y: 293
            text: qsTr("OK")
            activeFocusOnPress: false
        }
    
        property string connName: textInputConnName.text
        TextField {
            id: textInputConnName
            x: 180
            y: 40
            width: 360
            height: 20
            text: connNameIn
            placeholderText: connNamePlaceholder
            activeFocusOnPress: true
            inputMask: qsTr("")
            z: 1
            clip: true
            //cursorVisible: true
            focus: true
            KeyNavigation.tab: textInputServerName
            KeyNavigation.backtab: cancelButton
            KeyNavigation.priority: KeyNavigation.BeforeItem
            //selectByMouse: true
        }
    
        Rectangle {
            id: rectangleConnName
            x: 178
            y: 38
            width: 364
            height: 23
            color: "#e0e0e0"
            radius: 3
            border.width: 2
            border.color: "#000000"
        }
    
        property string serverName: textInputServerName.text
        TextField {
            id: textInputServerName
            x: 180
            y: 80
            width: 360
            height: 20
            text: serverNameIn
            placeholderText: serverNamePlaceholder
            inputMask: qsTr("")
            clip: true
            z: 1
           // cursorVisible: false
            KeyNavigation.tab: textInputShareName
            KeyNavigation.backtab: textInputConnName
            KeyNavigation.priority: KeyNavigation.BeforeItem
           // selectByMouse: true
        }
    
        Rectangle {
            id: rectangleServerName
            x: 178
            y: 78
            width: 364
            height: 23
            color: "#e0e0e0"
            radius: 3
            border.width: 2
            border.color: "#000000"
        }
    
        property string shareName: textInputShareName.text
        TextField {
            id: textInputShareName
            x: 180
            y: 120
            width: 360
            height: 20
            text: shareNameIn
            placeholderText: shareNamePlaceholder
            inputMask: qsTr("")
            //cursorVisible: false
            z: 1
            clip: true
            KeyNavigation.tab: textInputDomainName
            KeyNavigation.backtab: textInputServerName
            KeyNavigation.priority: KeyNavigation.BeforeItem
            //selectByMouse: true
        }
    
        Rectangle {
            id: rectangleShareName
                x: 178
                y: 119
                width: 364
                height: 23
                color: "#e0e0e0"
                radius: 3
                border.color: "#000000"
                border.width: 2
            }
    
        property string username: textInputUsername.text
        TextField {
            id: textInputUsername
            x: 180
            y: 200
            width: 360
            height: 20
            text: usernameIn
            placeholderText: usernamePlaceholder
            inputMask: qsTr("")
            //cursorVisible: false
            z: 1
            clip: true
            KeyNavigation.tab: textInputPassword
            KeyNavigation.backtab: textInputDomainName
            KeyNavigation.priority: KeyNavigation.BeforeItem
            //selectByMouse: true
        }
    
        Rectangle {
            id: rectangleUsername
            x: 178
            y: 198
            width: 364
            height: 23
            color: "#e0e0e0"
            radius: 3
            border.color: "#000000"
            border.width: 2
        }
    
        property string password: textInputPassword.text
        TextField {
            id: textInputPassword
            x: 180
            y: 240
            width: 360
            height: 20
            text: passwordIn
            echoMode: TextInput.Password
            inputMask: qsTr("")
            placeholderText: passwordPlaceholder
            //cursorVisible: false
            z: 1
            clip: true
            KeyNavigation.tab: okButton
            KeyNavigation.backtab: textInputUsername
            KeyNavigation.priority: KeyNavigation.BeforeItem
            //selectByMouse: true
        }
    
        Rectangle {
            id: rectanglePassword
            x: 178
            y: 239
            width: 364
            height: 23
            color: "#e0e0e0"
            radius: 3
            border.color: "#000000"
            border.width: 2
        }
    
        property string domainName: textInputDomainName.text
        TextField {
            id: textInputDomainName
            x: 180
            y: 160
            width: 360
            height: 20
            text: domainNameIn
            inputMask: qsTr("")
            placeholderText:  domainNamePlaceholder
            //cursorVisible: false
            z: 1
            clip: true
            KeyNavigation.tab: textInputUsername
            KeyNavigation.backtab: textInputShareName
            KeyNavigation.priority: KeyNavigation.BeforeItem
            //selectByMouse: true
        }
    
        Rectangle {
            id: rectangleDomainName
            x: 178
            y: 159
            width: 364
            height: 23
            color: "#e0e0e0"
            radius: 3
            border.color: "#000000"
            border.width: 2
        }
    }
    
    
    
    1 Reply Last reply
    0
    • CharlieGC Offline
      CharlieGC Offline
      CharlieG
      wrote on last edited by
      #2

      Hi,

      I had almost the same problem. In my case, I wanted translate a string in ListModel and qsTr("MyString") didn't work. I have solved the problem with using QT_TR_NOOP("MyString"). Have you tested ?

      Bye & good luck.

      Charlie

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JDGXNV
        wrote on last edited by
        #3

        I'm not sure how that would work in this case. We will give it a shot. These are static strings defined within the QML itself - nothing fancy like a list view.

        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