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. Qml, how to parse text to number

Qml, how to parse text to number

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 9.4k 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.
  • S Offline
    S Offline
    spode
    wrote on 15 Jun 2011, 14:10 last edited by
    #1

    i have a Text { text: "15"; id: label }. how do i parse the text into number to make some verification (if(label's text is minor than 15) add 1 to label's text and write it into label's text)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billouparis
      wrote on 15 Jun 2011, 15:31 last edited by
      #2

      Maybe you can write a simple javascript function in your current scope.
      @function convertToNumber(string)
      {
      return parseInt(string)
      }@
      And then call the function in your if condition expression?
      Bill

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on 15 Jun 2011, 18:14 last edited by
        #3

        you are a qt's dragon! =)
        so, i need to learn javascript. I miss it too!

        just a question: where must i write this function...and how can i call it?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          billouparis
          wrote on 16 Jun 2011, 09:24 last edited by
          #4

          You may be able to write it inside your current scope ie.
          The following code is working on my PC, it is incrementing the string value "15" to string value "16":

          @Rectangle {
          width: 360
          height: 360
          Text {
          anchors.centerIn: parent
          text: incrementString("15");
          }

          function incrementString(string)
          {
                 var stringValue = String(parseInt(string) + 1);
                 return stringValue;
          }
          
          
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  Qt.quit();
              }
          }
          

          }
          @

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on 16 Jun 2011, 09:28 last edited by
            #5

            link @ http://doc.qt.nokia.com/4.7/qml-extending-types.html should help you on how to add functions and signal handlers to your qml code.

            1 Reply Last reply
            0

            1/5

            15 Jun 2011, 14:10

            • Login

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