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. Forgot how to display a number within a QString....
Forum Updated to NodeBB v4.3 + New Features

Forgot how to display a number within a QString....

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k 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.
  • P Offline
    P Offline
    ProgrammerAtHeart3344
    wrote on last edited by
    #1

    Yea, the title says it all, anyways, i haven't used QT or QString in awhile so i tried this: @ QString str = QString("%d").arg(attempts);
    ui.numTries->setText(str);
    @

    and what i got was the literal "%d", so idk

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      @
      QString str1 = QString::fromNumber(attempts);
      // or
      QString str2 = QString("%1").arg(attempts);
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        ProgrammerAtHeart3344
        wrote on last edited by
        #3

        ah thank you

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Or, use the %n in your string instead of %d. This one is very useful in cases where you need two or more different strings based on the value:

          @
          QString attemptsStr = tr("%n attempts").arg(attempts);
          @

          In your translation, you will be able to create different translations for your string based on singular or plural, and for some languages even more than those two (some languages have more than one plural form).

          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