destruction

How does Qt delete objects ? And what is the best way to store QObjects? [duplicate]

谁说胖子不能爱 提交于 2019-11-28 05:32:11
This question already has an answer here: Creating and deallocating a Qt widget object 2 answers I heard that objects in Qt will automatically delete their children, I want to know what will happen in those situations. #include <QApplication> #include <QLabel> #include <QHBoxLayout> #include <QWidget> int main(int argc, char **argv) { QApplication app(argc, argv); /* QLabel label("label"); // Program will crash. Destruct order is 1. widget, 2. layout, 3. label QHBoxLayout layout; // But layout will be deleted twice QWidget widget; */ QWidget widget; // Program doesn't seem to crash but is it

How does Qt delete objects ? And what is the best way to store QObjects? [duplicate]

穿精又带淫゛_ 提交于 2019-11-27 05:35:38
问题 This question already has answers here : Creating and deallocating a Qt widget object (2 answers) Closed 6 years ago . I heard that objects in Qt will automatically delete their children, I want to know what will happen in those situations. #include <QApplication> #include <QLabel> #include <QHBoxLayout> #include <QWidget> int main(int argc, char **argv) { QApplication app(argc, argv); /* QLabel label("label"); // Program will crash. Destruct order is 1. widget, 2. layout, 3. label

Destruction order of static objects in C++

自古美人都是妖i 提交于 2019-11-26 15:22:39
Can I control the order static objects are being destructed? Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object? The static objects are destructed in the reverse order of construction. And the order of construction is very hard to control. The only thing you can be sure of is that two objects defined in the same compilation unit will be constructed in the order of definition. Anything else is more or less random. The other answers to this insist that it can't be done.

Destruction order of static objects in C++

假装没事ソ 提交于 2019-11-26 05:56:19
问题 Can I control the order static objects are being destructed? Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object? 回答1: The static objects are destructed in the reverse order of construction. And the order of construction is very hard to control. The only thing you can be sure of is that two objects defined in the same compilation unit will be constructed in the order