Qt: does “new without delete” cause memory leaks with controls?

前端 未结 5 1795
[愿得一人]
[愿得一人] 2020-12-14 18:24

I was looking at Qt example here:

and inside the constructor, they have:

 Window::Window()
 {
     editor = new QTextEdit();   // Memory leak?
     Q         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-14 19:05

    It won't get double deleted because of the .release() call.

    Note std::unique_ptr is replacing std::auto_ptr. Hopefully QT will support move semantics then that release() would be instead layout->addLayout(std::move(buttonLayout)) and without the call to move, you'd get a compile error.

提交回复
热议问题