Results 1 to 3 of 3

Thread: Closing QMainWindow

  1. #1
    Join Date
    Feb 2013
    Posts
    12
    Qt products
    Qt5
    Platforms
    Windows

    Default Closing QMainWindow

    I would close QMainWindow, when QDialog don't return QDialog::Accepted. I tried this->close(); and qApp->quit(); but it doesn't work. I would like run destructor while closing main window to delete pointers. Any ideas? I tried implement void closeEvent(QCloseEvent* event), but I don't know how do it correctly (remember about destructor).

  2. #2
    Join Date
    Nov 2012
    Location
    Kentucky, USA
    Posts
    46
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Closing QMainWindow

    Have the dialog emit a signal when the "cancel" button is clicked. Set up a connection from the signal to the slot in the mainwindow where you called the dialog to a slot in the mainwindow where you can call quit();

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Closing QMainWindow

    Quote Originally Posted by kalwi View Post
    I tried this->close();
    We have know idea what object this is.
    and qApp->quit(); but it doesn't work.
    Sure it does. You need to produce evidence of your claim.
    I would like run destructor while closing main window to delete pointers.
    This is unrelated. The destructor is run when the object is destroyed (by scope or explicit delete; except in cases of termination for unhandled exceptions). A typical QMainWindow instance is stack allocated and destroyed when it goes out of scope after the main program event loop exits. The event loop exits when qApp->quit() is called or (typically) when the last top-level window is hidden (closed).
    I tried implement void closeEvent(QCloseEvent* event), but I don't know how do it correctly (remember about destructor).
    closeEvent() has nothing to do with the destructor of the object. The QWidget::closeEvent() docs show exactly how to use it. The Application Example shows it in a complete application.

    Reduce your program to a small, single file, complete program that demonstrates the problem and post it here.

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2010, 17:07
  2. signals when closing QMainWindow
    By qmonkey in forum Qt Programming
    Replies: 3
    Last Post: 7th January 2010, 15:50
  3. How to handle 2 QmainWindow closing problems
    By narendra in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2009, 14:24
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. run function before closing QMainWindow
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 31st August 2006, 09:21

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.