[SOLVED] QLabel in main window is not updated/refreshed when modified in second window (QDialog)
-
Since you're running this in only one thread, the connection between signals and slots is direct. Here is a very simplified version of what happens when on_pushButton_SetText_clicked is called:
emit send_fromMain
ui->label_ShowText->setText(mainText);
qDebug () << "Received from mainwindow: " + mainText;
qDebug () << "Sent from main window";
Hope it helps
-
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....... -
@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);
} -
@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.