class MyClass : public QObject { Q_OBJECT public: MyClass() { // register cleanup handler for this object QMetaObjectCleanUp::setMetaObject(this); } ~MyClass() { // cleanup handler will delete this object } };
QStringList *stringList = new QStringList(); QMetaObjectCleanUp::setMetaObject(stringList);This example shows how to register an object other than a QObject subclass with QMetaObjectCleanUp. In this case, a new instance of `QStringList` is created and registered with `QMetaObjectCleanUp` to ensure automatic deletion of the instance. When the instance is destroyed, the cleanup handler will automatically delete that instance. Package library: Qt C++ Library.