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. [SOLVED] Convert listelement role to string

[SOLVED] Convert listelement role to string

Scheduled Pinned Locked Moved QML and Qt Quick
15 Posts 2 Posters 3.7k Views 1 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.
  • T Offline
    T Offline
    Traxx
    wrote on last edited by
    #5

    Sorry for the confusion but it is complete code.I actually try multiple way to get all string but none work and "namemodel.get()" is just one of the method i try.Previous tried some of the method below.Weird is if i use listview,all the listelement data is shown but i just want to compare the listelement data with other data only.Thanks very much

    @MainPage.qml
    function match() {
    if (topname.text == somename.text)
    testdialog.open()
    else {
    faildialog.open()
    }
    }
    Model {
    id: namemodel
    }
    Text {
    id: topname
    visible: false
    text: "2671634"
    }
    Text {
    id: somename
    visible: false
    text: namemodel.get(0).names //ONLY WORK ON FIRST LISTELEMENT
    }@

    @MainPage.qml
    function match() {
    if (topname.text == somename.text)
    testdialog.open()
    else {
    faildialog.open()
    }
    }
    Model {
    id: namemodel
    }
    Text {
    id: topname
    visible: false
    text: "2671634"
    }
    Text {
    id: somename
    visible: false
    text: namemodel.names
    }@

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #6

      try
      @
      ListModel {
      id: myModel
      ListElement{names: "354873595" }
      ListElement{names: "354700672" }
      ListElement{names: "359033560" }
      ListElement{names: "354875672" }
      ListElement{names: "352500609" }

          Component.onCompleted: {
              for(var i=0;i<count;i++)
                  console.log(myModel.get(i).names)
          }
      

      }
      @
      Do you see names are printed?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Traxx
        wrote on last edited by
        #7

        I never use console.log before but did you mean the qt message as shown?
        !http://imageshack.us/photo/my-images/89/3few.png/()!

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #8

          I can print all names, so myModel.get(i).names works fine.

          Starting H:\Qt\Qt5.2.0\5.2.0\msvc2010_opengl\bin\qmlscene.exe...
          354873595
          354700672
          359033560
          354875672
          352500609

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Traxx
            wrote on last edited by
            #9

            Thank you very very very much for your help.Qmlscene is not available since i use nokia QtSdk and my target is symbian.I will update the title if i manage to match the string.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Traxx
              wrote on last edited by
              #10

              I have change the MainPage a bit to follow Vicent007 example and it is not working but that is not the point.Why if i use "for(var i=0;i<count;i++)" the match() function is not working but if i comment it out it is working with either testdialog or faildialog open.If i use it,no dialog show so i assume the match() function not working.Thank you
              @MainPage.qml
              function match() {
              if (topname.text == somename.text)
              testdialog.open()
              else {
              faildialog.open()
              }
              }
              Model { //TO IMPORT Model.qml
              id: namemodel
              }
              Text {
              id: topname
              visible: false
              text: "2671634"
              }
              Text {
              id: somename
              visible: false
              }
              Component.onCompleted: {
              for(var i=0;i<count;i++)
              somename.text = namemodel.get(0).imeistring
              match() //FUNCTION

              }
              @

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vincent007
                wrote on last edited by
                #11

                { } is missing !!

                @
                Component.onCompleted: {
                for(var i=0;i<count;i++) {
                somename.text = namemodel.get(i).imeistring
                match() //FUNCTION
                }
                }
                @

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Traxx
                  wrote on last edited by
                  #12

                  Weird,putting {} didn't make difference.No dialog show if use the javascript.Once i comment it out the dialog show again.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vincent007
                    wrote on last edited by
                    #13

                    Did you add break points to track your code?

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Traxx
                      wrote on last edited by
                      #14

                      Errr,what is break point?

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Traxx
                        wrote on last edited by
                        #15

                        now i know,i will try

                        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