Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Displaying text & integer in a single label?



  • 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..


  • Moderators

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


  • Moderators

    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.


  • Moderators

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


Log in to reply