diff -rupN 2/orig/qapplication.cpp 2/new/qapplication.cpp --- 2/orig/qapplication.cpp Thu Dec 8 07:06:02 2011 +++ 2/new/qapplication.cpp Wed Jan 18 17:22:27 2012 @@ -974,6 +974,7 @@ void QApplicationPrivate::initialize() { QWidgetPrivate::mapper = new QWidgetMapper; QWidgetPrivate::allWidgets = new QWidgetSet; + QWidgetPrivate::topLevelWidgets = new QWidgetSet; #if !defined(Q_WS_X11) && !defined(Q_WS_QWS) && !defined(Q_WS_QPA) // initialize the graphics system - on X11 this is initialized inside @@ -2138,15 +2139,10 @@ void QApplication::setWindowIcon(const Q */ QWidgetList QApplication::topLevelWidgets() { - QWidgetList list; - QWidgetList all = allWidgets(); - - for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { - QWidget *w = *it; - if (w->isWindow() && w->windowType() != Qt::Desktop) - list.append(w); + if (QWidgetPrivate::topLevelWidgets){ + return QWidgetList(QWidgetPrivate::topLevelWidgets->toList()); } - return list; + return QWidgetList(); } /*! diff -rupN 2/orig/qwidget.cpp 2/new/qwidget.cpp --- 2/orig/qwidget.cpp Thu Dec 8 07:06:02 2011 +++ 2/new/qwidget.cpp Thu Jan 19 12:54:32 2012 @@ -1081,7 +1081,7 @@ void QWidget::setAutoFillBackground(bool QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid - +QWidgetSet *QWidgetPrivate::topLevelWidgets = 0; /***************************************************************************** QWidget utility functions @@ -1130,6 +1130,7 @@ struct QWidgetExceptionCleaner Q_UNUSED(d); #else QWidgetPrivate::allWidgets->remove(that); + QWidgetPrivate::topLevelWidgets->remove(that); if (d->focus_next != that) { if (d->focus_next) d->focus_next->d_func()->focus_prev = d->focus_prev; @@ -1388,6 +1389,9 @@ void QWidgetPrivate::init(QWidget *paren || QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) q->create(); + if (QWidgetPrivate::topLevelWidgets && q->isWindow() && q->windowType() != Qt::Desktop) { + QWidgetPrivate::topLevelWidgets->insert(q); + } QEvent e(QEvent::Create); QApplication::sendEvent(q, &e); @@ -1689,6 +1693,8 @@ QWidget::~QWidget() if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication QWidgetPrivate::allWidgets->remove(this); + if (QWidgetPrivate::topLevelWidgets) // might have been deleted by ~QApplication + QWidgetPrivate::topLevelWidgets->remove(this); QT_TRY { QEvent e(QEvent::Destroy); @@ -10071,6 +10077,12 @@ void QWidget::setWindowFlags(Qt::WindowF d->adjustQuitOnCloseAttribute(); } else { data->window_flags = flags; + } + + if (QWidgetPrivate::topLevelWidgets && isWindow() && windowType() != Qt::Desktop) { + QWidgetPrivate::topLevelWidgets->insert(this); + }else { + QWidgetPrivate::topLevelWidgets->remove(this); } } diff -rupN 2/orig/qwidget_p.h 2/new/qwidget_p.h --- 2/orig/qwidget_p.h Thu Dec 8 07:06:02 2011 +++ 2/new/qwidget_p.h Wed Jan 18 17:21:40 2012 @@ -708,6 +708,7 @@ public: // This should just ensure that all widgets are deleted by QApplication static QWidgetMapper *mapper; static QWidgetSet *allWidgets; + static QWidgetSet *topLevelWidgets; #if !defined(QT_NO_IM) QPointer ic; Qt::InputMethodHints imHints;