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. Beginners: how to show main widget after child exits
Forum Updated to NodeBB v4.3 + New Features

Beginners: how to show main widget after child exits

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 5.0k 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.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #3

    how can i do it?

    inside y I wrote this
    @
    #include "x.h"

    X t= new X;
    connect(this,this->close(), x, x.show());
    

    @
    could you please help me to formulate it?
    thanks

    [Edit: Added @ formatting tags -- mlong]

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #4

      close() is a slot, not a signal. You want to connect this from outside y:
      @
      connect(y, SIGNAL(destroyed()), x, SLOT(show()));
      @

      ... but that will only work if y is deleted when it's closed. That means, you need to set this attribute: Qt::WA_DeleteOnClose ...read http://qt-project.org/doc/qt-4.8/qwidget.html#close for more details.

      Do you have experience with Qt signals and slots? If not, I recommend following a good beginner's tutorial, such as: http://doc.trolltech.com/4.3/tutorial.html This will help you learn much faster.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #5

        My friend, I am newby but I know signals and slots.

        Lets make the task simpler on two steps. When I click on a button in Y form,
        I can not show x from inside y.

        in y, I have the header #include "x.h"

        Should I create a new instance of X
        @
        x *t = new x
        x.show();
        @

        should I make parent child?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prabuqt
          wrote on last edited by
          #6

          In show() method
          this->setVisible(true);

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SherifOmran
            wrote on last edited by
            #7

            but this code will be in y and @this@ would refer to y.
            Am I right?

            To hide x before y loads, I used this.hide() in a x function.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #8

              Let's make it clearer by calling the classes ParentWidget and ChildWidget.

              [quote author="SherifOmran" date="1347214503"]Should I create a new instance of X[/quote]You can create a new instance of the ChildWidget, and destroy it when it closes.
              @
              ChildWidget *child = new ChildWidget();
              child->setAttribute(Qt::WA_DeleteOnClose);
              @

              [quote author="SherifOmran" date="1347214503"]should I make parent child?[/quote]This is a good idea. If you delete the parent, then Qt will automatically delete the child also. This makes memory-management easier, and helps avoid memory leaks.
              @
              // Constructor
              ChildWidget::ChildWidget(QWidget *parent)
              : QWidget(parent)
              {
              // ...
              }
              @

              @
              // Creation, inside ParentWidget
              ChildWidget *child = new ChildWidget(this); // Sets "this" as the parent
              @

              [quote author="SherifOmran" date="1347219741"]but this code will be in y and @this@ would refer to y.
              Am I right?

              To hide x before y loads, I used this.hide() in a x function.[/quote] You are right -- if your code is in y, "this" refers to y.

              However, I would put the code in the parent, not the child. That's because the parent should manage the child; the child should not manage the parent.

              I would put this code in ParentWidget:

              @
              void ParentWidget::createChild()
              {
              ChildWidget *child = new ChildWidget(this);
              child->setAttribute(Qt::WA_DeleteOnClose);

              connect(child, SIGNAL(destroyed()), this, SLOT(show()));
              
              child->show();
              this->hide();
              

              }
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SherifOmran
                wrote on last edited by
                #9

                Thank you my friend, i will test and let you know.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SherifOmran
                  wrote on last edited by
                  #10

                  It does not work my friend. When I close the child, the parent is hidden and the software exists.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SherifOmran
                    wrote on last edited by
                    #11

                    I made a slot called reshow and connected the signal child destroyed to it. What i get is that

                    1- after closing the child window, it comes to the parent reshow slot, ignores the this.show command
                    2- goes to the parent destroyed function and destroy the parent

                    may be we need to drop event destroyed of the parent

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SherifOmran
                      wrote on last edited by
                      #12

                      I found the solution guys

                      http://www.thedazzlersinc.com/source/2012/06/04/qt-show-child-window-from-parent-vice-versa/

                      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