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

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

    Main reason - possibility of dynamic creating / removing widgets. QObject (and QWidget) desing as classes that could not have copy constructor, so you couldn't pass is in arguments (by value/reference). So using pointers in all cases makes code more simple and clear.

提交回复
热议问题