How to delete a QObject derived class from within one of its own methods
jimgilmour1
(Talk | contribs) m (minor format) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | {{ | + | [[Category:Qt]][[Category:How To]][[Category:Code Snippet]] |
| − | | | + | {{ArticleMetaData <!-- v1.2 --> |
| + | |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]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | ||
|platform= All | |platform= All | ||
| − | | | + | |devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) --> |
| − | | | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| − | | | + | |signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer --> |
| − | | | + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> |
|keywords= Qt, deleteLater | |keywords= Qt, deleteLater | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20-Jun-2010 | ||
| + | |author= [[User:Gnuton]] | ||
| + | <!-- The following are not in current metadata --> | ||
| + | |subcategory= | ||
}} | }} | ||
In order to delete a QObject-derived class from one of its own methods, developers have to use | In order to delete a QObject-derived class from one of its own methods, developers have to use | ||
| − | <code cpp> | + | <code cpp-qt> |
deleteLater(); | deleteLater(); | ||
</code> | </code> | ||
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. | 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 [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater | + | There are no problem if a signal or a method calls more than one time [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater QObject::deleteLater()] |
| − | Beginner developers sometimes | + | Beginner developers sometimes use |
| − | <code cpp> | + | <code cpp-qt> |
delete this; | delete this; | ||
</code> | </code> | ||
| − | and this is dangerous since the Qt event loop could invoke a method of the deleted class. Hence, the application or library | + | 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 | * Related Qt Documentation link | ||
Qt 4.6 [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater deleteLater()] | Qt 4.6 [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater deleteLater()] | ||
| − | [[Category:Qt]] | + | [[Category:Qt]][[Category:MeeGo Harmattan]] [[Category:Symbian]] |
Latest revision as of 04:17, 11 October 2012
Article Metadata
Compatibility
Platform(s): All
Article
Keywords: Qt, deleteLater
Created: gnuton
(20 Jun 2010)
Last edited: hamishwillee
(11 Oct 2012)
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()

