//--------- main.cpp -----------#include <qapplication.h>#include <qlayout.h>#include <qpushbutton.h>#include <qlabel.h>class DynWidget : public QWidget{ Q_OBJECTpublic: DynWidget( QWidget* parent = 0, const char* name = 0 ) : QWidget( parent, name ) { layout = new QVBoxLayout( this, 11, 6 ); layout->setAutoAdd( true ); QPushButton* addBut = new QPushButton( "New Label", this ); connect( addBut, SIGNAL( clicked() ), SLOT( addWidget() ) ); }public slots: void addWidget() { qDebug( "addWidget()" ); static int cnt = 1; QLabel* label = new QLabel( QString( "Label N %1" ).arg(cnt), this ); label->show(); cnt++; } private: QVBoxLayout* layout;};int main( int argc, char** argv ){ QApplication app( argc, argv ); DynWidget* dw = new DynWidget; dw->addWidget(); dw->addWidget(); dw->show(); app.connect( &app, SIGNAL( lastWindowClosed() ), SLOT( quit() ) ); return app.exec();}#include "main.moc"