C++ - Why do I create these widgets on the heap?

前端 未结 5 2177
有刺的猬
有刺的猬 2020-12-31 17:43

When creating a GUI with C++ and Qt you can create a label for example like this :

QLabel* label = new QLabel(\"Hey you!\", centralWidgetParent);
         


        
5条回答
  •  忘掉有多难
    2020-12-31 18:19

    Another thing to keep in mind is that Qt uses the so called pimpl paradigm where object data is implicitly shared and managed behind the class you actually instantiate. See here: http://qt-project.org/wiki/Dpointer

    The bottom line is that if you are allocating on the stack in order to avoid using the heap, Qt is just pulling a fast one on you and using the heap anyway.

提交回复
热议问题