Results 1 to 3 of 3

Thread: How do I distroy an object when clicking on the x?

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default How do I distroy an object when clicking on the x?

    Hi Gurus,

    I have a gui which calls another gui like so:

    Qt Code:
    1. if (userManager==0)
    2. {
    3. userManager = new UserManager();
    4.  
    5. }
    6. userManager->show();
    To copy to clipboard, switch view to plain text mode 

    This then launches the user manager window. So now how do I make sure that the ~UserManager gets executed when someone closes the window by clicking on the x?

    I know I should delete the reference to UserManager, but where do I do this?

    Thanks a million
    RT
    Last edited by wysota; 2nd April 2011 at 12:00. Reason: missing [code] tags

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How do I distroy an object when clicking on the x?

    You can use:
    Qt Code:
    1. userManager->setAttribute(Qt::WA_DeleteOnClose, true);
    To copy to clipboard, switch view to plain text mode 
    It will be deleted by QObject::deleteLater()

  3. #3
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I distroy an object when clicking on the x?

    Additionally, to make sure your Pointer is set to null after the window is closed, you could either use http://doc.trolltech.com/4.7/qobject.html#destroyed or a QPointer

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:07
  2. Replies: 1
    Last Post: 30th July 2010, 23:05
  3. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 14:28
  4. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 06:33
  5. how to distroy child window which parents is zero
    By rajesh in forum Qt Programming
    Replies: 4
    Last Post: 22nd June 2006, 08:52

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.