Sum Variable Problem
-
wrote on 20 Dec 2016, 12:13 last edited by
excuse me sorry i want to ask im a newbie want to learn Qt but i have some problem
i want to make Sum Variable that it will sum the variable and print it to the lineedit
here for mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->label->setNum(0); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { ui->label->setText("SempAK Naga Jantan :v"); } void MainWindow::on_pushButton_2_clicked() { int a,b,c; a= 2; b= 2; c=a+b; //QString hasil = ""; ui->label->setNum(QString::number(ui->lineEdit->text())); //ui->label->text().toInt(); }
i already watch the tutorial on youtube but i still dont understand , whats wrong in my code T_T
Thanks for help
Sorry for my bad english
-
wrote on 20 Dec 2016, 12:42 last edited by m.sue
Hi,
setNum
expects to get a number, you give itQString::number(ui->lineEdit->text())
which is a QString. And QString::number itself expects a number, you give itui->lineEdit->text()
which is a QString.
-Michael. -
wrote on 20 Dec 2016, 12:45 last edited by
What does the compiler say? It's usually a good place to start :-)
-
wrote on 20 Dec 2016, 12:56 last edited by
@Semara123 ... Welcome!
- I don't see you using "c" anywhere.
- Try using ui->label->setNum (ui->lineEdit->text ().toInt ());
For more information on QString goto:
http://doc.qt.io/qt-5/qstring.htmlDon't get discouraged. Qt is a large API and we all ask questions (even those of us who have been doing this for decades!) about it when we have problems. Good luck and have fun learning!
-
@Semara123 ... Welcome!
- I don't see you using "c" anywhere.
- Try using ui->label->setNum (ui->lineEdit->text ().toInt ());
For more information on QString goto:
http://doc.qt.io/qt-5/qstring.htmlDon't get discouraged. Qt is a large API and we all ask questions (even those of us who have been doing this for decades!) about it when we have problems. Good luck and have fun learning!
wrote on 20 Dec 2016, 13:26 last edited by@Buckwheat said in Sum Variable Problem:
ui->label->setNum (ui->lineEdit->text ().toInt ());
i already did it as you said but nothing happened :(
here is the code
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->label->setNum(0); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { ui->label->setText("SempAK Naga Jantan :v"); } void MainWindow::on_pushButton_2_clicked() { int a,b,c; a= 2; b= 2; c=a+b; //QString hasil = ""; ui->label->setNum (ui->lineEdit->text().toInt()); //ui->label->text().toInt(); }
Sorry to bother you T_T
and sorry for my bad english
-
wrote on 20 Dec 2016, 13:29 last edited by
Hi,
so what would you want in ui->label? The value ofc
, then just writeui->label->setNum(c)
.
-Michael. -
wrote on 20 Dec 2016, 14:42 last edited by
@m-sue ... If that is the intent! Otherwise you are just adding a number for the sake of adding a number! And to top it off, it is a local variable so the compiler will most likely throw it away during optimization
-
wrote on 20 Dec 2016, 15:20 last edited by Semara123
well now i already found the solution i forgot to delete this
case 2: _t->on_label_windowIconTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break; in moc_mainwindow.cpp
now everything runs normally
thank you everybody for helping me to fix this problem :D
-
well now i already found the solution i forgot to delete this
case 2: _t->on_label_windowIconTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break; in moc_mainwindow.cpp
now everything runs normally
thank you everybody for helping me to fix this problem :D
@Semara123 said in Sum Variable Problem:
moc_mainwindow.cpp
This is a generated file so running qmake will recreate it.
So hopefully it wont come back :) -
wrote on 21 Dec 2016, 13:10 last edited by
@Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D
-
@Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D
wrote on 21 Dec 2016, 14:23 last edited by@Buckwheat said in Sum Variable Problem:
@Semara123 ... you are manually editing your moc_ file? Wow! Ballsy! I just let the qmake regen it for me after I change my code. :D
LOL i think i didnt do anything :v, but i want to say thanks to you for helping me :D and thanks for other people :D
1/11