Difficulty in Qlabel and POO
-
I'm having trouble updating the value of label_Number, which I defined in my interface (myDialog.ui)
When I click on MainWindow::on_pushButton_clicked, through my MainWindow.MainWindow.h and .cpp:
void MainWindow::on_pushButton_clicked(){ obj.setNumber(ui->lineEdit_Number->text().toInt()); qDebug() << obj.getNumber(); myDialog ptr; ptr.exec(); }myDialog.h:
myDialog(Qwidget *parent) : QDialog(parent), ui(new Ui::myDialog){ ui->setupUi(this); myClass obj; ui->label_Number->setText(QString::number(obj.getNumber())); }In my case, I would have to create a Qlabel as private in my myDialog, and making a method to access
my ui->label_Number, being able to update the value directly from my MainWindow button, without having to create a button inside myDialog to refresh; -
I'm having trouble updating the value of label_Number, which I defined in my interface (myDialog.ui)
When I click on MainWindow::on_pushButton_clicked, through my MainWindow.MainWindow.h and .cpp:
void MainWindow::on_pushButton_clicked(){ obj.setNumber(ui->lineEdit_Number->text().toInt()); qDebug() << obj.getNumber(); myDialog ptr; ptr.exec(); }myDialog.h:
myDialog(Qwidget *parent) : QDialog(parent), ui(new Ui::myDialog){ ui->setupUi(this); myClass obj; ui->label_Number->setText(QString::number(obj.getNumber())); }In my case, I would have to create a Qlabel as private in my myDialog, and making a method to access
my ui->label_Number, being able to update the value directly from my MainWindow button, without having to create a button inside myDialog to refresh;@Gutoficiall
To pass the number fromMainWindowtomyDialog, either create a parameter for it in the dialog constructor (if the number is only passed at construction time) or write a setter method in the dialog which accepts a number and sets itsui->label_Numberfrom that. You do not need to export theQLabelfrom the dialog. -
@Gutoficiall
To pass the number fromMainWindowtomyDialog, either create a parameter for it in the dialog constructor (if the number is only passed at construction time) or write a setter method in the dialog which accepts a number and sets itsui->label_Numberfrom that. You do not need to export theQLabelfrom the dialog.@JonB
Thank you take the weight off my back and help clarify, I've been thinking for hours. I was lost here...