Namespaces
Variants
Actions
(Difference between revisions)

How to delete a QObject derived class from within one of its own methods

Jump to: navigation, search
m
m (add documentation link)
Line 15: Line 15:
 
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 problems if a signal or a method call more than one time [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater  QObject::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 sometime use  
+
Beginner developers sometimes  use  
 
<code cpp>
 
<code cpp>
 
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  will crash.
 
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 [http://doc.qt.nokia.com/4.6/qobject.html#deleteLater deleteLater()]
 
[[Category:Qt]]
 
[[Category:Qt]]

Revision as of 19:00, 20 June 2010

Article Metadata

Compatibility
Platform(s): All

Article
Keywords: Qt, deleteLater
Created: ()
Last edited: jimgilmour1 (20 Jun 2010)

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()

91 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved