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. Refresh entire form upon pressing a button
Forum Updated to NodeBB v4.3 + New Features

Refresh entire form upon pressing a button

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.7k 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.
  • R Offline
    R Offline
    russjohn834
    wrote on last edited by russjohn834
    #1

    Hi all,

    I have two forms - form1, form2.
    form1 has a QTableWidget which reads and shows xml entries in folder.

    form2 is a dialogue form, collect user data and save as xml.

    I need to implement the following:
    Pressing button1 in form2 save and close the window and immediately update Qtabletwidget in form1 with new values.

    I did the following in form2:

    void FormTwo::on_pushButton_clicked()
    {
    .
    .
    here read user data and save as xml file
    .
    .
    
    hide();
    FormOne *updatewindow = new FormOne(this);
    updatewindow->show();
    }
    

    So everytime a "new" FormOne will be created with updated contents. But I think this is a wrong way to proceed this

    Is there a way to implement this with signals and slots?

    Thanks in advance

    jsulmJ 1 Reply Last reply
    0
    • R russjohn834

      Hi all,

      I have two forms - form1, form2.
      form1 has a QTableWidget which reads and shows xml entries in folder.

      form2 is a dialogue form, collect user data and save as xml.

      I need to implement the following:
      Pressing button1 in form2 save and close the window and immediately update Qtabletwidget in form1 with new values.

      I did the following in form2:

      void FormTwo::on_pushButton_clicked()
      {
      .
      .
      here read user data and save as xml file
      .
      .
      
      hide();
      FormOne *updatewindow = new FormOne(this);
      updatewindow->show();
      }
      

      So everytime a "new" FormOne will be created with updated contents. But I think this is a wrong way to proceed this

      Is there a way to implement this with signals and slots?

      Thanks in advance

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

      @russjohn834 What is not clear from your description: should form1 always be there or only after closing form2?
      Who creates form2? If you say "form" do you mean a window or a widget in a window?
      If it is like this: form1 is always there and it creates form2 ,then you can use signals/slots. In form1 when you create form2 instance connect the "update" signal from form2 to a slot in form1. In that slot you then do what needs to be done in form1.

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

      R 1 Reply Last reply
      1
      • jsulmJ jsulm

        @russjohn834 What is not clear from your description: should form1 always be there or only after closing form2?
        Who creates form2? If you say "form" do you mean a window or a widget in a window?
        If it is like this: form1 is always there and it creates form2 ,then you can use signals/slots. In form1 when you create form2 instance connect the "update" signal from form2 to a slot in form1. In that slot you then do what needs to be done in form1.

        R Offline
        R Offline
        russjohn834
        wrote on last edited by
        #3

        @jsulm Thank you.
        I just figured out a way do this without signal & slot.

        I close form 1(btw , it is QMainwindow) when form 2 is created. Then when I press button form 2 will be closed and a new form 1 will be created. Like this:

        this->close(); ---->form 2
        MainWindow *back = new MainWindow(this);
        back->show();
        

        I hope this is fine.

        JonBJ 1 Reply Last reply
        0
        • R russjohn834

          @jsulm Thank you.
          I just figured out a way do this without signal & slot.

          I close form 1(btw , it is QMainwindow) when form 2 is created. Then when I press button form 2 will be closed and a new form 1 will be created. Like this:

          this->close(); ---->form 2
          MainWindow *back = new MainWindow(this);
          back->show();
          

          I hope this is fine.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @russjohn834

          MainWindow *back = new MainWindow(this);

          Although permissible, this creates a brand new main window instance, which is "unusual". It will also lose any state you had previously. You're also parenting the new main window off a "form" you have already close()d.

          If you really want to swap windows this way (QStackedWidget may be preferable), consider using show() & hide() instead, rather than total destruction & re-creation. If all you really want is to have one window/form/whatever at a time visible and user clicks to go between them, I think that QStackedWidget is going to be simpler & better for you. And you don't have to have your multiple main windows as the stack: you could have one main window, with its furniture, and have a stacked widget area on it, which is what gets switched.

          1 Reply Last reply
          2
          • R Offline
            R Offline
            russjohn834
            wrote on last edited by
            #5

            Thank you @JonB for your feedback

            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