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 <kai.koehne@qt.io>
This commit is contained in:
Friedemann Kleint 2016-05-24 15:47:19 +02:00 committed by Jani Heikkinen
parent 48d14c661d
commit 65ae3de2e1

View File

@ -44,6 +44,7 @@
#include <QtWidgets/QDialog>
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QVBoxLayout>
#if defined(Q_OS_WIN) || defined(Q_OS_WINCE)
# include <windows.h>
@ -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()
{