#include <qlabel.h>#include <qapplication.h>#include <qwidgetlist.h>class MyWidget : public QLabel{public: MyWidget() : QLabel( "", 0, "MyWidget" ), cnt(0) { resize( 200, 50 ); } void customEvent( QCustomEvent* ) { cnt++; setText( QString( "Counter : %1" ).arg(cnt) ); } void mousePressEvent( QMouseEvent* ) { QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it( *list ); QWidget *w; while ( (w=it.current()) != 0 ) { ++it; QApplication::postEvent( w, new QCustomEvent( 1001 ) ); } delete list; }private: int cnt;};int main( int argc, char** argv ){ QApplication app( argc, argv ); MyWidget w1, w2; w1.show(); w2.show(); QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); return app.exec();}