Results 1 to 3 of 3

Thread: Some quest about the closeEvent in QMainWindow

  1. #1
    Join Date
    Mar 2009
    Location
    Nanjing,China
    Posts
    40
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Some quest about the closeEvent in QMainWindow

    Hi all
    I have an application with muti MainWindow. and thie close way:
    The one way:
    Qt Code:
    1. void MWindow::fileExit()
    2. {
    3. close(TRUE);
    4. }
    To copy to clipboard, switch view to plain text mode 

    The another way:
    Qt Code:
    1. void MWindow::closeEvent(QCloseEvent* ce)
    2. {
    3. penv->m_WindowList->GoHead(); //the list of all QMainWindow
    4. do
    5. {
    6. if( pevn->m_WindowList->Object() == penv->currentWindow ) //
    7. {
    8. QMainWindow::closeEvent(ce);
    9. break;
    10. }
    11. }
    12. while(pevn->m_WindowList->GoNext())
    13. }
    To copy to clipboard, switch view to plain text mode 

    The Destroy funtion
    Qt Code:
    1. void MWindow::destroy()
    2. {
    3. //release the memory
    4. }
    To copy to clipboard, switch view to plain text mode 
    My question is:
    if I call the fileExit,it will call the destroy!
    and if I click the close button on the QMainWindow,it will call the closeEvent,but not
    call the destroy(),so my memery and GDI will leak!

    and I want to how,if I want to support the close button, how I can do to avoid the memory and GDI leak.

    Thanks.

    PS:my platform is WinXp,Qt336,MSVC6.0.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some quest about the closeEvent in QMainWindow

    Why should destroy() be called if you never call it yourself? Closing a window doesn't cause it to be deleted, it would be hard to retrieve any data from it then If you want such behaviour, then pass the DestructiveClose flag to each of the windows.
    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.


  3. #3
    Join Date
    Mar 2009
    Location
    Nanjing,China
    Posts
    40
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: Some quest about the closeEvent in QMainWindow

    you means if i want to call the destroy when click the close button on the QMainWindow, I neet set the WFlags Qt::WDestructiveClose?
    Isee,I use the QMainWindow in default, and I will try it later,
    Thanks

Similar Threads

  1. QMainWindow with QMainWindow
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2011, 07:07
  2. QSettings and closeEvent()
    By vito49 in forum Newbie
    Replies: 2
    Last Post: 13th October 2008, 16:18
  3. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  4. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 07:16
  5. Replies: 18
    Last Post: 22nd February 2006, 20:51

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.