Results 1 to 2 of 2

Thread: simple Question about QDialog::closeEvent(...)

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default simple Question about QDialog::closeEvent(...)

    Hi all, one would assume that closeEvent is called whenever the window/dialog is closed. I experimented around with a Dialog whose geometry I wanted to save. I had previously thought that the QDialog::accept() and QDialog::reject() slots indirectly invoke the closeEvent() since the dialog is closed after calling them per default. But closeEvent is only invoked when I hit the title bar close button. But shouldn't closeEvent be called no matter what leads to the closing of the dialog? After all it is _closed_ and one would expect closeEvent to be called!

    example: main.cpp

    Thanx in advance

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

    mentalmushroom (9th March 2018)

  3. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple Question about QDialog::closeEvent(...)

    Because the accept and reject impl look like this(notice the close helper):
    Qt Code:
    1. void QDialog::done(int r)
    2. {
    3. Q_D(QDialog);
    4. hide();
    5. setResult(r);
    6. d->close_helper(QWidgetPrivate::CloseNoEvent);
    7. emit finished(r);
    8. if (r == Accepted)
    9. emit accepted();
    10. else if (r == Rejected)
    11. emit rejected();
    12. }
    13.  
    14. /*!
    15.   Hides the modal dialog and sets the result code to \c Accepted.
    16.  
    17.   \sa reject() done()
    18. */
    19.  
    20. void QDialog::accept()
    21. {
    22. done(Accepted);
    23. }
    24.  
    25. /*!
    26.   Hides the modal dialog and sets the result code to \c Rejected.
    27.  
    28.   \sa accept() done()
    29. */
    30.  
    31. void QDialog::reject()
    32. {
    33. done(Rejected);
    34. }
    To copy to clipboard, switch view to plain text mode 
    If you would like the closeEvent to get called then don't use their slots.
    Or you could use the finished signal instead the close event.

    The close_helper is implemented in QWidget.cpp

  4. The following user says thank you to marcel for this useful post:

    momesana (16th February 2008)

Similar Threads

  1. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  2. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  3. simple hello world question
    By chap19150 in forum Qt Programming
    Replies: 12
    Last Post: 11th July 2006, 19:42
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.