Results 1 to 4 of 4

Thread: Is it bad to delete an object during its event handler?

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is it bad to delete an object during its event handler?

    Hi,

    I have a function in which my application changes skins, and where it is necessary to use qDeleteAll() and remove all objects, then make new ones. The object that triggers this function is a button, say Button1. When the button is pressed I get the following error (Qt Creator):

    Qt Code:
    1. app-stderr:QObject: Do not delete object, 'Button1', during its event handler!
    To copy to clipboard, switch view to plain text mode 

    I haven't experienced any Seg faults or other consequences but would like to know if this is in any way dangerous and if it is, how I can avoid it.

    Thanks in advance,
    codeslicer

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Is it bad to delete an object during its event handler?

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    codeslicer (30th December 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: Is it bad to delete an object during its event handler?

    Hmm thanks... except how I clear my form is using this:

    Qt Code:
    1. QObjectList childrenList = children();
    2. childrenList.removeAt(childrenList.indexOf(DoNotDeleteMeObject));
    3. ...
    4. qDeleteAll(childrenList);
    To copy to clipboard, switch view to plain text mode 

    Is there an alternative for qDeleteAll() which uses deleteLater()?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Is it bad to delete an object during its event handler?

    Quote Originally Posted by codeslicer View Post
    Is there an alternative for qDeleteAll() which uses deleteLater()?
    Qt Code:
    1. foreach (QObject* child, childrenList)
    2. child->deleteLater();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Changing default event handler name
    By mabeeh in forum Newbie
    Replies: 1
    Last Post: 21st April 2008, 15:18
  2. event handler
    By mattia in forum Newbie
    Replies: 10
    Last Post: 8th November 2007, 12:54
  3. Replies: 2
    Last Post: 4th August 2007, 04:31
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. delete custom event
    By Dmitry in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2006, 16:55

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.