[SOLVED] QLabel in main window is not updated/refreshed when modified in second window (QDialog)
-
Hey anyone help me out!!
Say there is main window and dialog window after dialogue window execution main window having tablewidget needs to be get updated. Here in my case the problem is it is creating one more new main window with updated data and old main window still running in background....... -
@Npsad Well, why do you create a new main window instead of updating the existing one?
-
@jsulm well that's what I want to update old main window itself how to update it instead of updating it in new main window.
-
@Npsad Sorry, but as long as you do not show your code nobody will be able to say you what you're doing wrong.
-
@jsulm sorry for that can you please share me a code of how to update old UI itself
-
@Npsad Are you aware that you are asking a question nobody can answer? I have no idea what you want to update. Show your code then we can tell you what is wrong.
-
@jsulm okk that code is in middle of application
So am passing sample code where say here main window is having line edit and dialog window on click mainw window line edit should get updated with value hope it is clear....MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
Dialog* obj = new Dialog(this);
obj->show();
}
void MainWindow::updatemthd(QString Upd)
{qDebug()<<Upd;
ui->lineEdit->repaint();
ui->lineEdit->setText(Upd);
}Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}Dialog::~Dialog()
{
delete ui;
}void Dialog::on_pushButton_clicked()
{
QString Upd="updated";
MainWindow* n= new MainWindow();
n->updatemthd(Upd);
} -
is this your first time programming?
-
@J.Hilk yup can you please give me a solution for this
-
@Npsad said in [SOLVED] QLabel in main window is not updated/refreshed when modified in second window (QDialog):
MainWindow* n= new MainWindow();
Why do you create a new MainWindow instance here?
This needs to be done in a different way: your dialog should NOT access MainWindow directly (it should not even know anything about MainWindow - software design). Instead it should emit a signal, this signal is connected in MainWindow to a slot and that slot then updates the UI. -
@jsulm thanks for that in actual application I tried with that it's working..... thanks