PDA

View Full Version : add two integers



Gishan
8th September 2012, 07:17
how to add to integers,what is the easiest way to do it?

ui->label2->setText(ui->plainTextEdit->toPlainText());
int A,B,C;
QString S1(ui->label->selectedText());
QString S2(ui->label->selectedText());
A = S1.toInt();
B = S2.toInt();
C = static_cast<int>(A)+ B; //need to add A + B but it gives 0 to me

pkj
8th September 2012, 07:32
Use QLabel::text(). Refer qt documentation available online or through qt4 assistant.

Gishan
8th September 2012, 07:44
please can u make this runnable
i just need to add A and B

Lesiok
8th September 2012, 08:44
how to add to integers,what is the easiest way to do it?

ui->label2->setText(ui->plainTextEdit->toPlainText());
int A,B,C;
QString S1(ui->label->selectedText());
QString S2(ui->label->selectedText());
A = S1.toInt();
B = S2.toInt();
C = static_cast<int>(A)+ B; //need to add A + B but it gives 0 to me
The easiest way to add two integers is :

int A,B,C;
C = A+B;

You have a problem with getting text from widget or converting QString to int not with adding ints. Do you know what it is a debugger and how to use it (running program step by step) ?