Results 1 to 10 of 10

Thread: Returning from Dialog

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Returning from Dialog

    Quote Originally Posted by SSqt5.2 View Post
    In my code i have never called hide(), or Delete() for any dialog or widgets. the dialog disappears after event on OK/Cancel button.
    So how come when you launch a dialog, the main window disappears?

    Maybe it would be best if you provided a minimal compilable example reproducing the problem?

    This code seems to work fine:

    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. class MainWindow : public QMainWindow {
    4. Q_OBJECT
    5. public:
    6. MainWindow() {
    7. QPushButton *pb = new QPushButton("Press");
    8. setCentralWidget(pb);
    9. connect(pb, SIGNAL(clicked()), this, SLOT(showDialog()));
    10.  
    11. }
    12. public slots:
    13. void showDialog() {
    14. QDialog dlg;
    15. QPushButton *pb = new QPushButton("Show another dialog");
    16. QVBoxLayout *l = new QVBoxLayout(&dlg);
    17. l->addWidget(pb);
    18. connect(pb, SIGNAL(clicked()), this, SLOT(showDialog2()));
    19. dlg.exec();
    20. }
    21. void showDialog2() {
    22. QDialog dlg;
    23. QPushButton *pb = new QPushButton("Close");
    24. QVBoxLayout *l = new QVBoxLayout(&dlg);
    25. l->addWidget(pb);
    26. connect(pb, SIGNAL(clicked()), &dlg, SLOT(accept()));
    27. dlg.exec();
    28. }
    29. };
    30.  
    31. #include "main.moc"
    32.  
    33. int main(int argc, char **argv) {
    34. QApplication app(argc, argv);
    35. MainWindow mw;
    36. mw.show();
    37. app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 17th October 2014 at 12:25.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    SSqt5.2 (20th October 2014)

Similar Threads

  1. Replies: 2
    Last Post: 6th July 2011, 15:20
  2. Function returning a QHBoxLayout
    By aomegax in forum Newbie
    Replies: 5
    Last Post: 16th August 2010, 18:19
  3. Returning const &
    By frenk_castle in forum Newbie
    Replies: 2
    Last Post: 24th November 2009, 07:01
  4. returning a string
    By mickey in forum General Programming
    Replies: 2
    Last Post: 3rd February 2008, 19:41
  5. Replies: 3
    Last Post: 18th October 2007, 08:07

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
  •  
Qt is a trademark of The Qt Company.