From e0810d8052741f49d269514d40d683c45edfd975 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 13 Nov 2020 10:54:11 +0100 Subject: Avoid calling QQuickItemPrivate's methods if QQIP is incomplete In QQuickWindow, we instantiate QQuickPaletteProviderPrivateBase, which in turn instantiates its updateChildrenPalettes method, which then calls QQuickItemPrivate::inheritPalette. However, QQIP is an incomplete type at this point. Including qquickitemprivate_p.h would currently create a cyclic dependency, and breaking that dependency might mean outlining performance sensitive code. Thus we instead (ab)use the fact that updateChildrenPalettes is virtual, do nothing in the specialization for QQuickWindow and instead implement the method in the same way as an override in QQuickWindowPrivate. Task-number: QTBUG-88457 Change-Id: I49b357d7a67f1945a4d3c25e8cabd428d1454aa7 Reviewed-by: Volker Hilsheimer --- src/quick/items/qquickpaletteproviderprivatebase_p.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/quick/items/qquickpaletteproviderprivatebase_p.h') diff --git a/src/quick/items/qquickpaletteproviderprivatebase_p.h b/src/quick/items/qquickpaletteproviderprivatebase_p.h index 8f8251f251..a600a23ce6 100644 --- a/src/quick/items/qquickpaletteproviderprivatebase_p.h +++ b/src/quick/items/qquickpaletteproviderprivatebase_p.h @@ -344,10 +344,21 @@ void QQuickPaletteProviderPrivateBase::setCurrentColorGroup() template void QQuickPaletteProviderPrivateBase::updateChildrenPalettes(const QPalette &parentPalette) { - if (auto root = rootItem(*itemWithPalette())) { - for (auto &&child : root->childItems()) { - if (Q_LIKELY(child)) { - getPrivate(*child)->inheritPalette(parentPalette); + if constexpr (std::is_same_v && std::is_same_v) { + /* QQuickWindowPrivate instantiates this template, but does not include QQuickItemPrivate + * This causes an error with the QQuickItemPrivate::inheritPalette call below on MSVC in + * static builds, as QQuickItemPrivate is incomplete. To work around this situation, we do + * nothing in this instantiation of updateChildrenPalettes and instead add an override in + * QQuickWindowPrivate, which does the correct thing. + */ + Q_UNREACHABLE(); // You are not supposed to call this function + return; + } else { + if (auto root = rootItem(*itemWithPalette())) { + for (auto &&child : root->childItems()) { + if (Q_LIKELY(child)) { + getPrivate(*child)->inheritPalette(parentPalette); + } } } } -- cgit v1.2.3