QMdi: Don't emit subWindowActivated during StyleChange handling.
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 <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
5c6b2ede3b
commit
a6e5ccbe22
@ -164,6 +164,7 @@
|
||||
#include <private/qmacstyle_mac_p.h>
|
||||
#endif
|
||||
#include <QMdiArea>
|
||||
#include <QScopedValueRollback>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -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)
|
||||
@ -3008,6 +3013,7 @@ void QMdiSubWindow::changeEvent(QEvent *changeEvent)
|
||||
|
||||
if (d->isActive)
|
||||
d->ensureWindowState(Qt::WindowActive);
|
||||
if (d->activationEnabled)
|
||||
emit windowStateChanged(oldState, windowState());
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
@ -204,6 +205,7 @@ private slots:
|
||||
void task_182852();
|
||||
void task_233197();
|
||||
void task_226929();
|
||||
void styleChange();
|
||||
};
|
||||
|
||||
void tst_QMdiSubWindow::initTestCase()
|
||||
@ -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"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user