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

前端 未结 5 2144
有刺的猬
有刺的猬 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:39

    Because that is how Qt was designed. I realize that's not a very satisfying answer, but Qt was simply designed as "widgets are created on the heap, and parents are responsible for deleting their children".

    Realize that the origins of Qt are old, older than what we consider "modern C++".

提交回复
热议问题