引用楼主zl39049979于2010-03-24 15:57发表的 QT或C++中类对象与类指针 :
在QT的教材中常常一个类对象有时直接用他的指针定义比如,QWidget* a=new QWidget;有时却用类对象 QLabel a(parent),请问有什么区别和好处吗?我知道用指针可以在析构的时候直接DELETE
类指针 use heap memory
类对象 use stack memory
Always use 类指针 for Qt GUI components.
QWidget* a=new QWidget;
QLabel * a = new QLabel(parent);
the reason is that Qt has garbage collector which helps clear heap memory.
You do not need to do the delete. Using 类对象 in Qt for GUI components
can cause crashes.