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?

0

1 Answer 1

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)); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.