From 65ae3de2e12ab0d9b28699b419e3d3aa8af3a267 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 24 May 2016 15:47:19 +0200 Subject: [PATCH] Fix tst_QListView::setCurrentIndexAfterAppendRowCrash(). The test was half-ported from Qt 4 and #ifdefed out depending on WINVER. When it became active, it failed since it queries the window handle too early in the process. Move the code sending the message into showEvent() to ensure a window handle exists and parent the listview properly to prevent a leaking toplevel. Change-Id: I74aa9ddfd0e88dd31e9258400fc3e473b6e0d92e Reviewed-by: Kai Koehne --- .../itemviews/qlistview/tst_qlistview.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 651172e79f..98cc9b29ed 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #if defined(Q_OS_WIN) || defined(Q_OS_WINCE) # include @@ -111,7 +112,7 @@ private slots: void scrollBarAsNeeded(); void moveItems(); void wordWrap(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && WINVER >= 0x0500 +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) void setCurrentIndexAfterAppendRowCrash(); #endif void emptyItemSize(); @@ -1456,8 +1457,10 @@ class SetCurrentIndexAfterAppendRowCrashDialog : public QDialog public: SetCurrentIndexAfterAppendRowCrashDialog() { -#if WINVER >= 0x0500 - listView = new QListView(); + setWindowTitle(QTest::currentTestFunction()); + listView = new QListView(this); + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(listView); listView->setViewMode(QListView::IconMode); model = new QStandardItemModel(this); @@ -1466,12 +1469,16 @@ public: timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(buttonClicked())); timer->start(1000); + } +protected: + void showEvent(QShowEvent *event) override + { + QDialog::showEvent(event); DWORD lParam = 0xFFFFFFFC/*OBJID_CLIENT*/; DWORD wParam = 0; if (const HWND hwnd =getHWNDForWidget(this)) SendMessage(hwnd, WM_GETOBJECT, wParam, lParam); -#endif } private slots: @@ -1488,16 +1495,13 @@ private: QStandardItemModel *model; QTimer *timer; }; -#endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) && WINVER >= 0x0500 -// This test only makes sense on windows 2000 and higher. void tst_QListView::setCurrentIndexAfterAppendRowCrash() { SetCurrentIndexAfterAppendRowCrashDialog w; w.exec(); } -#endif +#endif // Q_OS_WIN && !Q_OS_WINCE && !Q_OS_WINRT void tst_QListView::emptyItemSize() {