Skip to content

Commit

Permalink
QMdi: Don't emit subWindowActivated during StyleChange handling.
Browse files Browse the repository at this point in the history
The handling of StyleChange de-maximizes the child window temporarily,
which was emitting subWindowActivated.
This would crash lokalize, because deactivating a window means deleting
the widgets associated with it, and style-change handling is done in
QApplication by looping over QApplication::allWidgets, which would then
contain dangling pointers.

Full valgrind log at https://bugs.kde.org/show_bug.cgi?id=271494#c7

Change-Id: Ifb24032cde2cd470dcae7cd553ec5ab45a919dd6
Reviewed-by: Friedemann Kleint <[email protected]>
  • Loading branch information
dfaure authored and The Qt Project committed Mar 25, 2013
1 parent 5c6b2ed commit a6e5ccb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/widgets/widgets/qmdisubwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
#include <private/qmacstyle_mac_p.h>
#endif
#include <QMdiArea>
#include <QScopedValueRollback>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -2789,6 +2790,10 @@ bool QMdiSubWindow::event(QEvent *event)
bool wasShaded = isShaded();
bool wasMinimized = isMinimized();
bool wasMaximized = isMaximized();
// Don't emit subWindowActivated, the app doesn't have to know about our hacks
const QScopedValueRollback<bool> activationEnabledSaver(d->activationEnabled);
d->activationEnabled = false;

ensurePolished();
setContentsMargins(0, 0, 0, 0);
if (wasMinimized || wasMaximized || wasShaded)
Expand Down Expand Up @@ -3008,7 +3013,8 @@ void QMdiSubWindow::changeEvent(QEvent *changeEvent)

if (d->isActive)
d->ensureWindowState(Qt::WindowActive);
emit windowStateChanged(oldState, windowState());
if (d->activationEnabled)
emit windowStateChanged(oldState, windowState());
}

/*!
Expand Down
31 changes: 31 additions & 0 deletions tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Q_DECLARE_METATYPE(Qt::WindowState);
Q_DECLARE_METATYPE(Qt::WindowStates);
Q_DECLARE_METATYPE(Qt::WindowType);
Q_DECLARE_METATYPE(Qt::WindowFlags);
Q_DECLARE_METATYPE(QMdiSubWindow*);

class tst_QMdiSubWindow : public QObject
{
Expand Down Expand Up @@ -204,6 +205,7 @@ private slots:
void task_182852();
void task_233197();
void task_226929();
void styleChange();
};

void tst_QMdiSubWindow::initTestCase()
Expand Down Expand Up @@ -2018,6 +2020,35 @@ void tst_QMdiSubWindow::task_226929()
QVERIFY(sub1->isMaximized());
}

void tst_QMdiSubWindow::styleChange()
{
QMdiArea mdiArea;
mdiArea.show();
QVERIFY(QTest::qWaitForWindowExposed(&mdiArea));

QMdiSubWindow *sub1 = mdiArea.addSubWindow(new QTextEdit);
sub1->showMaximized();

QMdiSubWindow *sub2 = mdiArea.addSubWindow(new QTextEdit);
sub2->showMinimized();

mdiArea.setActiveSubWindow(sub1);

QTest::qWait(100);

qRegisterMetaType<QMdiSubWindow *>();
QSignalSpy spy(&mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)));
QVERIFY(spy.isValid());

QEvent event(QEvent::StyleChange);
QApplication::sendEvent(sub1, &event);
QApplication::sendEvent(sub2, &event);

// subWindowActivated should NOT be activated by a style change,
// even if internally QMdiSubWindow un-minimizes subwindows temporarily.
QCOMPARE(spy.count(), 0);
}

QTEST_MAIN(tst_QMdiSubWindow)
#include "tst_qmdisubwindow.moc"

0 comments on commit a6e5ccb

Please sign in to comment.