[vlc-commits] [Git][videolan/vlc][master] qml: use incubator with mode `AsynchronousIfNested` instead of `createObject()` in delegates

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri May 8 17:57:11 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
9dcc03a3 by Fatih Uzunoglu at 2026-05-08T17:16:23+00:00
qml: use incubator with mode `AsynchronousIfNested` instead of `createObject()` in delegates

As noted in the docs, `AsynchronousIfNested` is explained to be [1]:

> The creation will occur asynchronously if part of a nested
> asynchronous creation, or synchronously if not.

For that reason, we should not be using `createObject()` in view
delegates since if the delegate is being instantiated asynchronously,
such custom object should also be instantiated asynchronously.

[1] https://doc.qt.io/qt-6/qqmlincubator.html#details

- - - - -


2 changed files:

- modules/gui/qt/widgets/qml/MediaCover.qml
- modules/gui/qt/widgets/qml/TableViewDelegateExt.qml


Changes:

=====================================
modules/gui/qt/widgets/qml/MediaCover.qml
=====================================
@@ -202,10 +202,30 @@ Item {
 
     property Widgets.PlayCover _playCoverItem
 
+    property var _playCoverItemIncubator
+
     onPlayCoverShowPlayChanged: {
         // NOTE: We are lazy loading the component when this gets visible and it stays loaded.
         //       We could consider unloading it when visible goes to false.
-        if (playCoverShowPlay && !_playCoverItem)
-            _playCoverItem = playCoverComponent.createObject(root)
+        if (playCoverShowPlay && !_playCoverItem && !_playCoverItemIncubator) {
+            // https://doc.qt.io/qt-6/qqmlincubator.html#details
+            const incubator = playCoverComponent.incubateObject(root, {}, 1 /* QQmlIncubator::AsynchronousIfNested */)
+            _playCoverItemIncubator = incubator
+
+            // https://doc.qt.io/qt-6/qml-qtqml-component.html#incubateObject-method
+            if (incubator.status !== Component.Ready) {
+                incubator.onStatusChanged = function(status) {
+                    if (status === Component.Ready) {
+                        root._playCoverItem = incubator.object
+                        // Incubator should be garbage collected, we don't need it anymore:
+                        root._playCoverItemIncubator = null
+                    }
+                }
+            } else {
+                root._playCoverItem = incubator.object
+                // Incubator should be garbage collected, we don't need it anymore:
+                root._playCoverItemIncubator = null
+            }
+        }
     }
 }


=====================================
modules/gui/qt/widgets/qml/TableViewDelegateExt.qml
=====================================
@@ -251,15 +251,26 @@ T.Control {
 
                 Component.onCompleted: {
                     const del = modelData.model.colDelegate || delegate.defaultDelegate
-                    item = del.createObject(loader, {
+                    // https://doc.qt.io/qt-6/qqmlincubator.html#details
+                    const incubator = del.incubateObject(loader, {
                             cellModel: cellModel,
                             width: Qt.binding(() => loader.width),
                             height: Qt.binding(() => loader.height),
-                        }
+                        }, 1 /* QQmlIncubator::AsynchronousIfNested */
                     )
-                    if (item.artworkTextureProvider) {
-                        delegate.artworkTextureProvider = Qt.binding(() => item.artworkTextureProvider)
+
+                    // https://doc.qt.io/qt-6/qml-qtqml-component.html#incubateObject-method
+                    if (incubator.status !== Component.Ready) {
+                        incubator.onStatusChanged = function(status) {
+                            if (status === Component.Ready) {
+                                loader.item = incubator.object
+                            }
+                        }
+                    } else {
+                        loader.item = incubator.object
                     }
+
+                    delegate.artworkTextureProvider = Qt.binding(() => loader?.item?.artworkTextureProvider ?? null)
                 }
                 Component.onDestruction: {
                     item?.destroy()



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/9dcc03a34a3b3d43f525da6525db083d08128560

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/9dcc03a34a3b3d43f525da6525db083d08128560
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list