Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QLabel in main window is not updated/refreshed when modified in second window (QDialog)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QLabel in main window is not updated/refreshed when modified in second window (QDialog)

Scheduled Pinned Locked Moved General and Desktop
18 Posts 6 Posters 7.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Npsad

    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.......

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #9

    @Npsad Well, why do you create a new main window instead of updating the existing one?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    N 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Npsad Well, why do you create a new main window instead of updating the existing one?

      N Offline
      N Offline
      Npsad
      wrote on last edited by
      #10

      @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.

      jsulmJ 1 Reply Last reply
      0
      • N Npsad

        @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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #11

        @Npsad Sorry, but as long as you do not show your code nobody will be able to say you what you're doing wrong.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Npsad Sorry, but as long as you do not show your code nobody will be able to say you what you're doing wrong.

          N Offline
          N Offline
          Npsad
          wrote on last edited by
          #12

          @jsulm sorry for that can you please share me a code of how to update old UI itself

          jsulmJ 1 Reply Last reply
          0
          • N Npsad

            @jsulm sorry for that can you please share me a code of how to update old UI itself

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #13

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            N 1 Reply Last reply
            0
            • jsulmJ jsulm

              @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.

              N Offline
              N Offline
              Npsad
              wrote on last edited by
              #14

              @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);
              }

              J.HilkJ jsulmJ 2 Replies Last reply
              0
              • N Npsad

                @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);
                }

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #15

                @Npsad

                is this your first time programming?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                N 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Npsad

                  is this your first time programming?

                  N Offline
                  N Offline
                  Npsad
                  wrote on last edited by
                  #16

                  @J.Hilk yup can you please give me a solution for this

                  1 Reply Last reply
                  0
                  • N Npsad

                    @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);
                    }

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    N 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @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.

                      N Offline
                      N Offline
                      Npsad
                      wrote on last edited by
                      #18

                      @jsulm thanks for that in actual application I tried with that it's working..... thanks

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved