0

I wrote this code to change label text. but id does not change:

void DateTimes::on_btnHourP_clicked()
{
    int h=ui->txtHour->text().toInt();
    if(h==24)
        h=-1;
    ui->txtHour->setText(QString::number(h++));//*
}

but my label text not change. then I change the code to this:

void DateTimes::on_btnHourP_clicked()
{
    int h=ui->txtHour->text().toInt();
    if(h==24)
        h=-1;
    h+=1;//*
    ui->txtHour->setText(QString::number(h));//*
}  

then the text of my label is change.
why?! could anyone solve my question?

H.Ghassami
  • 1,012
  • 2
  • 21
  • 42

1 Answers1

4

Incremet operator ++ will use the value and then increment. If you want to use the incremented h value within the same expresion. use ++h.

ui->txtHour->setText(QString::number(++h));
MBN
  • 304
  • 1
  • 12