当前位置:网站首页>[Qt5] QT QWidget immediately appears and disappears

[Qt5] QT QWidget immediately appears and disappears

2022-07-06 03:29:00 qq_ forty-three million four hundred and seventy-eight thousand

Solution :

  1. If you use the method of generating objects on the stack , namely QWidget w. The object is automatically destroyed after the function is executed , Naturally, there is no . Unless it is generated in the parent function or recorded as a class member , So that the object will not be automatically destroyed after the end of the sub function .
  2. If you allocate objects in heap memory , namely QWidget* w = new QWidget. The object will not be automatically destroyed after the function is executed , Don't set widget Of parent Under the circumstances ( After setting widget Not alone ), It should not disappear , But be careful about memory leaks . Be careful , Smart pointers are used here, such as sharedptr Still can't , Because after the end of the function body , Smart pointer object destruction , Destroy the objects allocated on the heap at the same time , Methods can be used 1 How to solve .
原网站

版权声明
本文为[qq_ forty-three million four hundred and seventy-eight thousand]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060325478047.html