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]How to add numbers inside a text element
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to add numbers inside a text element

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 2.4k 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.
  • J Offline
    J Offline
    jr_jags
    wrote on last edited by
    #1

    Im trying to add numbers previewed in a text element
    @Text {
    id: sum1
    x: 137
    y: 389
    width: 80
    height: 20
    color: "#eadfdf"
    text: "1"
    font.pixelSize: 12
    }

    Text {
    id: sum2
    x: 137
    y: 389
    width: 80
    height: 20
    color: "#eadfdf"
    text: "1"
    font.pixelSize: 12
    }

    Text {
    id: answer
    x: 137
    y: 389
    width: 80
    height: 20
    color: "#eadfdf"
    text: sum1.text + sum2.text
    font.pixelSize: 12
    }@

    It gave me a wrong answer,
    How can i use text elements to hold my numbers and add them alltogether?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Diph
      wrote on last edited by
      #2

      Hack. :P

      text: sum1.text1 + sum2.text1

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

        ahh sir, can you please explain to me, what does the * sign stands for?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Diph
          wrote on last edited by
          #4

          It's just multiplication which forces type conversion to number. :)

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jr_jags
            wrote on last edited by
            #5

            oh so i can use that if the number is declared, what if the number is from an API storage that had its own value?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Diph
              wrote on last edited by
              #6

              Did some research... You can also use Javascript's parseInt method:

              @text: parseInt(sum1.text) + parseInt(sum2.text)@

              http://www.w3schools.com/jsref/jsref_parseInt.asp

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jr_jags
                wrote on last edited by
                #7

                @//if i change the value of sum2 to a number from a API sotrage
                Text {
                id: sum2
                x: 137
                y: 389
                width: 80
                height: 20
                color: "#eadfdf"
                text: Storage.getSettingScore("settingScore","valueScore")
                font.pixelSize: 12
                } @

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jr_jags
                  wrote on last edited by
                  #8

                  WOW, Thank you man, the ParseInt keyword is the key for my formula, THANKS!!!!!!! :D

                  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