You are not logged in.

1

Thursday, July 31st 2014, 3:02am

Adding integers.

Ok so it seems like the simplest thing in the world to do, add two ints to display a running total. The first hit displays properly. The second one displays a huge weird number. Googled and googled and can't come up with an answer. Help.

Source code

1
2
3
4
5
6
7
8
int sub
     
    int amount = ui->lineEdit->text().toInt();
sub=sub+amount;
      ui->lineEdit->setText("");
      ui->lineEdit->setFocus();
      ui->textEdit->append(QString::number(amount));
      ui->label_3->setText (QString::number(sub));

2

Sunday, August 3rd 2014, 9:34pm

Global variable solved this problem.

3

Thursday, August 28th 2014, 6:54am

Glad you solved it but suggest you try

static int amount;
amount = ui->lineEdit->text().toInt();



As I understand it, that will keep the value between each time you call the function/slot
I would say preferable to global stuff