Results 1 to 5 of 5

Thread: QDialog - show(), exec() and blocking

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    22
    Thanks
    1

    Default QDialog - show(), exec() and blocking

    Hi,

    I just came across a widget with the following code in one of its methods (slightly paraphrased):
    Qt Code:
    1. void MyWidget::showDialog()
    2. {
    3. Ui_Dialog dui;
    4. QDialog dialog;
    5. dui.setupUi(&dialog);
    6. // some more stuff to setup dialog
    7. dialog.show();
    8. if (dialog.exec() == QDialog::Accepted)
    9. {
    10. // store dialog content somewhere
    11. }
    12. qDebug() << "END";
    13. }
    To copy to clipboard, switch view to plain text mode 

    I'm rather surprised by the show() followed by an exec() which I've never seen before in this way.
    What seems to happen is that the new dialog does not block the parent widget, because of the show().
    I don't understand why a previous show() should have an impact on the behaviour of exec().
    MyWidget remains responsive yet the rest of showDialog() does not get executed (no "END" is printed) until the dialog is closed (then it does get printed).
    So basically the method seems to pause at the exec() yet MyWidget is responsive?!
    Of course this leads to segmentation faults, if MyWidget gets closed before the dialog is closed.

    If I comment out the show(), the exec() properly blocks and everything works pretty much as I would expect.

    Is there any reason to use show() and exec() in this way (in any situation)?
    Is it a wanted behaviour that a previous show() influences exec() in this way?
    Isn't the correct way to open a dialog and remain responsive to connect a slot to the dialog's finished() method (and have the dialog be a member instead of a local variable)?

    Best,
    xdn
    Last edited by xdn; 9th April 2015 at 14:00.

Similar Threads

  1. QSqlQuery exec blocking function
    By reinki0013 in forum Qt Programming
    Replies: 5
    Last Post: 13th August 2012, 18:00
  2. Replies: 9
    Last Post: 25th March 2011, 21:22
  3. exec() not blocking, derived QDialog, Qt 4.4.3
    By wdezell in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2009, 18:56
  4. problem with show/exec of Qdialog
    By dudedude in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 11:20
  5. QDialog: show() and exec() together in constructor?
    By Teuniz in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2007, 11:43

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.