Search code examples
c++qt

Incorporate setText and setNum into a label in Qt?


I have a few very simple lines of code of the slot for a horizontal slider:

void newwindow::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setNum(value);
}

Now, instead of the label just displaying a number (such as "11" or "42"), how would I make it display "Value: 11"?

I think that I would probably have to incorporate setText into this too, although I don't know how I would do that.

There's probably a really simple solution but I haven't found it yet. Any help?


Solution

  • Use QString::number to convert int to QString :

     ui->label->setText(QString("Value: ") + QString::number(value));