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. Cannot Translate ListElement "name" Variables
Forum Update on Monday, May 27th 2025

Cannot Translate ListElement "name" Variables

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqtquickqtquick 1.0translatetranslation
3 Posts 2 Posters 696 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.
  • C Offline
    C Offline
    closx
    wrote on 13 Jun 2019, 07:32 last edited by
    #1

    Hello all,
    I am trying to translate my qt application for first time. Everything does OK, but only ListElement's wont translate. Part of code that I am trying to translate:

    id: leftMenu
                model:tmodel
            }
            ListModel{
                id: tmodel
                ListElement{
                    name: QT_TR_NOOP("Left Window")
                    st:"LeftWindow"
    
                }
                ListElement{
                    name: QT_TR_NOOP("Right Window")
                    st:"RightWindow"
                }
            }
            Text {
                text: qsTr(tmodel.get(0).name);
                }
    

    When I run lupdate, it shows only ones with the QT_TR_NOOP("").
    If I edit qsTr code as,

    Text {
                text: qsTr("hello");
                }
    

    It returns a qsTr on QT Linguist. I guess, it means, "tmodel.get(0).name" does not return a string value.
    What can I do guys?

    bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
    tag me (like @closx) if you are answering to me, so I can notice :D

    K 1 Reply Last reply 13 Jun 2019, 07:39
    0
    • C closx
      13 Jun 2019, 07:32

      Hello all,
      I am trying to translate my qt application for first time. Everything does OK, but only ListElement's wont translate. Part of code that I am trying to translate:

      id: leftMenu
                  model:tmodel
              }
              ListModel{
                  id: tmodel
                  ListElement{
                      name: QT_TR_NOOP("Left Window")
                      st:"LeftWindow"
      
                  }
                  ListElement{
                      name: QT_TR_NOOP("Right Window")
                      st:"RightWindow"
                  }
              }
              Text {
                  text: qsTr(tmodel.get(0).name);
                  }
      

      When I run lupdate, it shows only ones with the QT_TR_NOOP("").
      If I edit qsTr code as,

      Text {
                  text: qsTr("hello");
                  }
      

      It returns a qsTr on QT Linguist. I guess, it means, "tmodel.get(0).name" does not return a string value.
      What can I do guys?

      K Offline
      K Offline
      KroMignon
      wrote on 13 Jun 2019, 07:39 last edited by
      #2

      @closx in you ListElement items, replace QT_TR_NOOP() with qsTr() and remote qsTr() from the text item.

      Something like this

      ListModel{
          id: tmodel
          ListElement{
              name: qsTr("Left Window")
              st:"LeftWindow"
      
          }
          ListElement{
              name: qsTr("Right Window")
              st:"RightWindow"
          }
      }
      
      Repeater {
          model:tmodel
          Text {
              text: name
          }    
      }
      

      Perhaps you need to update your translation file.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      C 1 Reply Last reply 13 Jun 2019, 07:46
      4
      • K KroMignon
        13 Jun 2019, 07:39

        @closx in you ListElement items, replace QT_TR_NOOP() with qsTr() and remote qsTr() from the text item.

        Something like this

        ListModel{
            id: tmodel
            ListElement{
                name: qsTr("Left Window")
                st:"LeftWindow"
        
            }
            ListElement{
                name: qsTr("Right Window")
                st:"RightWindow"
            }
        }
        
        Repeater {
            model:tmodel
            Text {
                text: name
            }    
        }
        

        Perhaps you need to update your translation file.

        C Offline
        C Offline
        closx
        wrote on 13 Jun 2019, 07:46 last edited by
        #3

        @KroMignon LOVE YOU!
        Thank you very much, worked w/out problems, and made me understand my mistake.
        note: Needed to update .ts file and release .qm file after changing code.

        bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
        tag me (like @closx) if you are answering to me, so I can notice :D

        1 Reply Last reply
        0

        1/3

        13 Jun 2019, 07:32

        • Login

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