From 7f74a613f83f35fc5204857868378ed404628e46 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Wed, 18 Nov 2020 09:59:12 +0100 Subject: tst_qqmlproperty: Fix interfaceBinding crash on MSVC 2019 Change-Id: I4bb4a66b7ccca838e058962bbc297659b273c78e Done-with: Fabian Kosmale Fixes: QTBUG-84416 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmlproperty/interfaces.h | 16 ++++++++++++---- tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qqmlproperty/interfaces.h b/tests/auto/qml/qqmlproperty/interfaces.h index 2c06c5f594..f89b47efbe 100644 --- a/tests/auto/qml/qqmlproperty/interfaces.h +++ b/tests/auto/qml/qqmlproperty/interfaces.h @@ -30,8 +30,11 @@ #define INTERFACES_H #include +#include struct Interface { + // non-virtual, non-QObject interfaces are not supported + virtual ~Interface() {}; }; QT_BEGIN_NAMESPACE @@ -39,7 +42,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(Interface, MyInterface_iid); QT_END_NAMESPACE -class A : public QObject, Interface { +class A : public QObject, public Interface { Q_OBJECT Q_INTERFACES(Interface) }; @@ -57,6 +60,9 @@ struct Interface2 { Q_GADGET QML_INTERFACE +public: + // non-virtual, non-QObject interfaces are not supported + virtual ~Interface2() {}; }; QT_BEGIN_NAMESPACE @@ -64,7 +70,8 @@ QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(Interface2, MyInterface2_iid); QT_END_NAMESPACE -class A2 : public QObject, Interface2 { +class A2 : public QObject, public Interface2 +{ Q_OBJECT QML_ELEMENT Q_INTERFACES(Interface2) @@ -94,7 +101,8 @@ public: } void setInterface(Interface* interface) { - QObject* object = reinterpret_cast(interface); + QObject* object = dynamic_cast(interface); // we know that we only get an A + QVERIFY(object); m_testValue = object->property("i").toInt(); emit testValueChanged(); if (m_interface == interface) @@ -135,7 +143,7 @@ public: } void setInterface(Interface2* interface2) { - QObject* object = reinterpret_cast(interface2); + QObject* object = dynamic_cast(interface2); m_testValue = object->property("i").toInt(); emit testValueChanged(); if (m_interface == interface2) diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 1fd0b1a7d1..10a4881579 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -2146,15 +2146,23 @@ void tst_qqmlproperty::nullPropertyBinding() void tst_qqmlproperty::interfaceBinding() { -#if defined(Q_CC_MSVC) - QSKIP("Test disabled due to crashing. See QTBUG-84416"); -#endif qmlRegisterInterface("Interface", 1); qmlRegisterType("io.qt.bugreports", 1, 0, "A"); qmlRegisterType("io.qt.bugreports", 1, 0, "B"); qmlRegisterType("io.qt.bugreports", 1, 0, "C"); qmlRegisterType("io.qt.bugreports", 1, 0, "InterfaceConsumer"); + // Currently registration macros such as QML_ELEMENT are broken when there's multiple inheritance (QTBUG-88623) + // So these types have to be registered again. + // TODO: Fix QTBUG-88623 and remove this hack + qmlRegisterInterface("Interface2", 2); + qmlRegisterType("io.qt.bugreports", 2, 0, "A2"); + qmlRegisterType("io.qt.bugreports", 2, 0, "A2"); + qmlRegisterType("io.qt.bugreports", 2, 0, "B2"); + qmlRegisterType("io.qt.bugreports", 2, 0, "C2"); + qmlRegisterType("io.qt.bugreports", 2, 0, "InterfaceConsumer2"); + + const QVector urls = { testFileUrl("interfaceBinding.qml"), testFileUrl("interfaceBinding2.qml") @@ -2164,7 +2172,8 @@ void tst_qqmlproperty::interfaceBinding() QQmlEngine engine; QQmlComponent component(&engine, url); QScopedPointer root(component.create()); - QVERIFY(root); + QVERIFY2(root, qPrintable(component.errorString())); + QCOMPARE(root->findChild("a1")->property("testValue").toInt(), 42); QCOMPARE(root->findChild("a2")->property("testValue").toInt(), 43); QCOMPARE(root->findChild("a3")->property("testValue").toInt(), 44); -- cgit v1.2.3