Results 1 to 2 of 2

Thread: qdialog hide and show problem

  1. #1
    Join Date
    Jun 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default qdialog hide and show problem

    Hey! I have a mainwindow and 2 dialogs(namely dialog2 and dialog3). I need to go to dialog2 from mainwindow while hiding mainwindow and i need to goto dialog3 from dialog2 while hiding dialog2.
    Here is my code:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "dialog2.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. MainWindow::~MainWindow()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void MainWindow::on_pushButton_clicked()
    18. {
    19. hide();
    20. Dialog2 ptr;
    21. ptr.setModal(true);
    22. ptr.exec();
    23. show();
    24. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "dialog2.h"
    2. #include "ui_dialog2.h"
    3. #include "dialog3.h"
    4. #include <QDebug>
    5.  
    6. Dialog2::Dialog2(QWidget *parent) :
    7. QDialog(parent),
    8. ui(new Ui::Dialog2)
    9. {
    10. ui->setupUi(this);
    11. }
    12.  
    13. Dialog2::~Dialog2()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void Dialog2::on_pushButton_clicked()
    19. {
    20. hide();
    21. Dialog3 ptr;
    22. ptr.setModal(true);
    23. ptr.exec();
    24. show();
    25.  
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "dialog3.h"
    2. #include "ui_dialog3.h"
    3.  
    4. Dialog3::Dialog3(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::Dialog3)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. Dialog3::~Dialog3()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

    PROBLEM:
    When I close dialog3 , dialog2 is not showing up(it's destructor is being called) and mainwindow shows up. Help me out.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qdialog hide and show problem

    Please show that code that makes the connections between the pushbuttons and the slots in the dialogs, and also the code that shows what happens to close the dialogs (i.e. what causes them to return from exec()). As far as I can see, the code you have posted will not show the behavior you observe.

    The main issue I see is that you are creating the dialogs without parents, which makes them top-level widgets and not children of the main window or dialog that created them. Because they are parentless, they could have independent lifetimes. Try creating dialog2 as a child of main window, and dialog3 as a child of dialog2 and see if the behavior changes.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Hide/Show problem
    By premroxx in forum Newbie
    Replies: 1
    Last Post: 9th September 2011, 15:33
  2. Replies: 5
    Last Post: 25th March 2010, 12:14
  3. Hide and Show problem in master layout
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 16:04
  4. problem with show/exec of Qdialog
    By dudedude in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 11:20
  5. hide/show screen update problem
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2006, 17:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.