From 346aff98d18e6ad437e48565fd1cc74153bf529e Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 23 Oct 2023 18:32:08 +0200 Subject: [PATCH] using QQuickItemPrivate::inDestructor for Qt >= 6.5 instead of the componentComplete hack done in ~QskQuickItem --- src/controls/QskMainView.cpp | 2 +- src/controls/QskPopup.cpp | 2 +- src/controls/QskQuick.cpp | 15 +++++++++++++++ src/controls/QskQuick.h | 1 + src/controls/QskQuickItem.cpp | 5 +++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/controls/QskMainView.cpp b/src/controls/QskMainView.cpp index ced25d56..cad52776 100644 --- a/src/controls/QskMainView.cpp +++ b/src/controls/QskMainView.cpp @@ -103,7 +103,7 @@ void QskMainView::focusInEvent( QFocusEvent* event ) { if ( auto focusItem = nextItemInFocusChain( true ) ) { - if ( qskIsItemComplete( focusItem ) + if ( !qskIsItemInDestructor( focusItem ) && qskIsAncestorOf( this, focusItem ) ) { focusItem->setFocus( true ); diff --git a/src/controls/QskPopup.cpp b/src/controls/QskPopup.cpp index 54cd4060..3d680049 100644 --- a/src/controls/QskPopup.cpp +++ b/src/controls/QskPopup.cpp @@ -527,7 +527,7 @@ void QskPopup::focusInEvent( QFocusEvent* event ) if ( auto focusItem = nextItemInFocusChain( true ) ) { - if ( qskIsItemComplete( focusItem ) + if ( !qskIsItemInDestructor( focusItem ) && qskIsAncestorOf( this, focusItem ) ) { focusItem->setFocus( true ); diff --git a/src/controls/QskQuick.cpp b/src/controls/QskQuick.cpp index 436f6f88..43967d29 100644 --- a/src/controls/QskQuick.cpp +++ b/src/controls/QskQuick.cpp @@ -47,6 +47,21 @@ bool qskIsItemComplete( const QQuickItem* item ) return QQuickItemPrivate::get( item )->componentComplete; } +bool qskIsItemInDestructor( const QQuickItem* item ) +{ + auto d = QQuickItemPrivate::get( item ); + +#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 ) + return d->inDestructor; +#else + /* + QskQuickItem sets componentComplete to false in its destructor, + but for other items we will will return the wrong information + */ + return !d->componentComplete; +#endif +} + bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem* child ) { if ( item == nullptr || child == nullptr ) diff --git a/src/controls/QskQuick.h b/src/controls/QskQuick.h index 4141483e..458edf4f 100644 --- a/src/controls/QskQuick.h +++ b/src/controls/QskQuick.h @@ -24,6 +24,7 @@ template< typename T > class QList; of QQuickItem. */ +QSK_EXPORT bool qskIsItemInDestructor( const QQuickItem* ); QSK_EXPORT bool qskIsItemComplete( const QQuickItem* ); QSK_EXPORT bool qskIsAncestorOf( const QQuickItem* item, const QQuickItem* child ); QSK_EXPORT bool qskIsTabFence( const QQuickItem* ); diff --git a/src/controls/QskQuickItem.cpp b/src/controls/QskQuickItem.cpp index 41be05a5..76d786ac 100644 --- a/src/controls/QskQuickItem.cpp +++ b/src/controls/QskQuickItem.cpp @@ -180,6 +180,11 @@ QskQuickItem::~QskQuickItem() We set componentComplete to false, so that operations that are triggered by detaching the item from its parent can be aware of the about-to-delete state. + + Note, that since Qt >= 6.5 this information is stored + in QQuickItemPrivate::inDestructor. + + s.a: qskIsItemInDestructor */ d_func()->componentComplete = false;