Test::Test(QWidget *parent) : QDialog(parent){ m_label.setParent(this); m_label.setText("hello");}
#include <QtGui>#include <qDebug>class MyLabel : public QLabel {public: MyLabel( QWidget * parent = 0 ) : QLabel(parent) {} virtual ~MyLabel( void ) { qDebug() << "destruct MyLabel"; } };class MyFrame : public QFrame {public: MyFrame( QWidget * parent = 0 ) : QFrame(parent) {} virtual ~MyFrame( void ) { qDebug() << "destruct MyFrame"; } };class MyDialog : public QDialog {public: MyDialog( QWidget * parent = 0 ) : QDialog(parent) { mFrame.setParent(this); mLabel.setParent(&mFrame); }// data MyLabel mLabel; MyFrame mFrame;};int main(int argc, char *argv[]){ QApplication a(argc, argv); MyDialog dlg; return 0;}
C++ (Qt)MyClass::MyMethod(){ Dialog * d = new Dialog()...... delete d;}