[vlc-commits] [Git][videolan/vlc][master] qt: declaratively assign the model in `VideoAllSubDisplay.qml`
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Mar 24 21:27:04 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
e5ee3cd5 by Fatih Uzunoglu at 2025-03-24T21:04:40+00:00
qt: declaratively assign the model in `VideoAllSubDisplay.qml`
Imperatively assigning the model is problematic here, because
the model may be accessed before it is assigned.
With declarative approach, it is the QML engine's responsibility
make sure the model is assigned at appropriate time before it
is accessed.
Qt documentation states that [1]:
> If a parent is not provided to createObject(), a reference to the
> returned object must be held so that it is not destroyed by the
> garbage collector. This is true regardless of whether Item::parent
> is set afterwards, because setting the Item parent does not change
> object ownership. Only the graphical parent is changed.
Since the old model is no longer referenced anymore after
`MainCtx.grouping` changes, this approach should be fine.
I have tested this on both Qt 6.2 and 6.8.
[1] https://doc.qt.io/qt-6/qml-qtqml-component.html#createObject-method
- - - - -
1 changed file:
- modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
Changes:
=====================================
modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
=====================================
@@ -42,7 +42,29 @@ VideoAll {
// Private
- property var _meta: null
+ readonly property QtObject _meta: {
+ const grouping = MainCtx.grouping;
+
+ if (grouping === MainCtx.GROUPING_NAME)
+ return groupComponent.createObject()
+ else if (grouping === MainCtx.GROUPING_FOLDER)
+ return folderComponent.createObject()
+ else
+ return videoComponent.createObject()
+ }
+
+ on_MetaChanged: {
+ // Purge the objects that are pending deletion, to have the model
+ // preservation behavior aligned with 460cd3d4. If we don't do
+ // this, the QML/JS engine would pick an arbitrary time to collect
+ // garbage, potentially leading having all models alive at the
+ // same time:
+ // > having the three models always present, means that the data (at
+ // > least the first chuck) is loaded 3 times, and will be reloaded
+ // > 3 times every time a database event triggers a refresh of the
+ // > model.
+ gc() // `QJSEngine::GarbageCollectionExtension` is installed by default
+ }
// Signals
@@ -64,19 +86,6 @@ VideoAll {
// Functions
- function _updateMetaModel(groupping) {
- if (root._meta)
- root._meta.destroy()
-
- if (groupping === MainCtx.GROUPING_NAME) {
- root._meta = groupComponent.createObject(root)
- } else if (groupping === MainCtx.GROUPING_FOLDER) {
- root._meta = folderComponent.createObject(root)
- } else {
- root._meta = videoComponent.createObject(root)
- }
- }
-
function getLabelGroup(model, string) {
if (!model) return ""
@@ -104,15 +113,6 @@ VideoAll {
// Children
- Connections {
- target: MainCtx
- function onGroupingChanged() {
- root._updateMetaModel(MainCtx.grouping)
- }
- }
-
- Component.onCompleted: root._updateMetaModel(MainCtx.grouping)
-
Component {
id: videoComponent
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e5ee3cd520eb1c7a7d68ed86ee3fd8b5d9c100b8
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e5ee3cd520eb1c7a7d68ed86ee3fd8b5d9c100b8
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list