Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is a QT connection constructed by the connect() statement automatically cleaned up, when its creator ( for example a QAction) is deleted, or must I do this on my own, by saving connections as instances of my class and deleting them in my destructor?

Given is the following example:

MYClass::MYClass() {
    connect(this, &QAction::triggered, this, &MYClass::clicked);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
379 views
Welcome To Ask or Share your Answers For Others

1 Answer

The documentation for the destructor of QObject says

All signals to and from the object are automatically disconnected

here: https://doc.qt.io/qt-5/qobject.html#dtor.QObject

So no you don't have do disconnect your connections. When any QObject object is destructed it will clean this up for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...