#include#include #include QPushButton *pushButton = new QPushButton("Delete MyClass"); MyClass *myClass = new MyClass(); QObject::connect(pushButton, SIGNAL(clicked()), myClass, SLOT(remove()));
#includeIn this example, a QTimer is started to trigger every second. After five seconds, QTimer::singleShot() is called to schedule its deletion using deleteLater(). This code is part of the Qt framework's library.QTimer *timer = new QTimer(); timer->start(1000); QTimer::singleShot(5000, timer, SLOT(deleteLater()));