|
|
От: |
Skorodum
|
|
| Дата: | 10.10.25 11:54 | ||
| Оценка: | +1 | ||
QObject::~QObject()
All signals to and from the object are automatically disconnected, and any pending posted events for the object are removed from the event queue.
#include <QObject>
#include <QDebug>
#include <QCoreApplication>
#include <QTimer>
class Object : public QObject
{
Q_OBJECT
signals:
void mySignal();
public:
Object(QObject *parent = nullptr) : QObject(parent)
{
QTimer::singleShot(10, this, [this](){
emit mySignal();
deleteLater();
});
connect(this, &QObject::destroyed, this, []{ qDebug() << "Object destroyed"; });
connect(this, &Object::mySignal, this, []{ qDebug() << "Signal received"; });
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
const auto *obj = new Object(&app); // owned by app, but there is no double delete
QObject::connect(obj, &QObject::destroyed, &app, &QCoreApplication::quit);
return app.exec();
}
#include "main.moc"Signal received
Object destroyed