How to delete a QObject derived class from within one of its own methods
jimgilmour1
(Talk | contribs) m (add code example category) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData) |
||
| Line 1: | Line 1: | ||
[[Category:Qt]][[Category:How To]][[Category:Code Examples]] | [[Category:Qt]][[Category:How To]][[Category:Code Examples]] | ||
| − | {{ | + | {{ArticleMetaData |
|id= | |id= | ||
|platform= All | |platform= All | ||
| Line 8: | Line 8: | ||
|creationdate=20-Jun-2010 | |creationdate=20-Jun-2010 | ||
|keywords= Qt, deleteLater | |keywords= Qt, deleteLater | ||
| + | |||
| + | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | ||
| + | |devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) --> | ||
| + | |signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) --> | ||
| + | |author=[[User:Gnuton]] | ||
}} | }} | ||
Revision as of 12:22, 24 June 2011
Article Metadata
Compatibility
Platform(s): All
Article
Keywords: Qt, deleteLater
Created: gnuton
(20 Jun 2010)
Last edited: hamishwillee
(24 Jun 2011)
In order to delete a QObject-derived class from one of its own methods, developers have to use
deleteLater();
Since this is a public slot, it can be connected to a signal or it can be just called in any method of the class.
There are no problem if a signal or a method calls more than one time QObject::deleteLater()
Beginner developers sometimes use
delete this;
and this is dangerous since the Qt event loop could invoke a method of the deleted class. Hence, the application or library will crash.
- Related Qt Documentation link
Qt 4.6 deleteLater()

