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. Displaying text & integer in a single label?
Qt 6.11 is out! See what's new in the release blog

Displaying text & integer in a single label?

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

    This is a total simple question I think, but:
    How do I display a string and a integer in a single label? I tried it to make it like this:
    @ int version = 1;
    ui->label_3->setText("Version", version);@
    or this:
    @ int version = 1;
    ui->label_3->setText("Version" & version);@
    ..or this:
    @ int version = 1;
    ui->label_3->setText("Version" + version);@
    Nothing seems to work..

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @
      int version = 1;
      ui->label_3->setText("Version" + QString::number(version));
      // or:
      ui->label_3->setText(QString("Version%1").arg(version));
      @

      (Z(:^

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        or
        @
        ui->label_3->setText("Version" + QLocale().toString(version));
        @
        if you care about local number formatting (like space after several zeros or local decimal separator), although in this case it's irrelevant.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Hey, cool, I didn't know about this one :-)

          (Z(:^

          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