Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Difference between QString::number() & QString::setNum()?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Difference between QString::number() & QString::setNum()?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 4.5k 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.
  • C Offline
    C Offline
    CAD_coding
    wrote on 2 May 2013, 06:56 last edited by
    #1

    Hi,
    I want to convert a double variable to a QString. I want to have a very strict control over the precision & accuracy. A faster method would be convenient. I have found these 2 functions : QString::number() & QString::setNum(). Both perform the conversion from double to a QString with user defined precision & formatting. So I wanted to know what is the difference between these 2 methods. There must be some difference that is why they have provided these 2 functions, right?
    Thank You.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 2 May 2013, 07:01 last edited by
      #2

      the one is static the other is not ;)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CAD_coding
        wrote on 3 May 2013, 05:37 last edited by
        #3

        Seriously is that the only difference?
        lol

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 3 May 2013, 05:46 last edited by
          #4

          [quote author="CAD_coding" date="1367559446"]Seriously is that the only difference?
          lol[/quote]Yes :) Conceptually, they are quite different.

          QString::number() creates a new string and returns it. It doesn't delete/change existing data. (Well, if you assign the return value to an old variable, then the old data is replaced... but that's due to the assignment operator, not QString::number()).

          QString::setNum() takes an existing string replaces its contents. The old data is gone.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CAD_coding
            wrote on 3 May 2013, 05:47 last edited by
            #5

            ok. Got it. :)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mickey
              wrote on 3 May 2013, 05:59 last edited by
              #6

              Can you tell me functions to convert string to double?

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 3 May 2013, 06:16 last edited by
                #7

                [quote author="mickey" date="1367560798"]Can you tell me functions to convert string to double?[/quote]
                did you even look once at the "docs":http://qt-project.org/doc/qt-4.8/qstring.html#toDouble?!

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mickey
                  wrote on 3 May 2013, 18:08 last edited by
                  #8

                  no this question came in mind just when I read this post.So I suddenly asked.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mickey
                    wrote on 3 May 2013, 18:11 last edited by
                    #9

                    But thanx for help.I am referring to docs.But did not come through this.

                    1 Reply Last reply
                    0

                    1/9

                    2 May 2013, 06:56

                    • Login

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