Unable to use a Loader item as a model in Silica PagedView

REPRODUCIBILITY: 100% (always)
OS VERSION: 5.0.0.68
HARDWARE: Sony Xperia XZ2
UI LANGUAGE: English
REGRESSION: don’t know

DESCRIPTION:

Possibly due to a bug in Silica, setting PagedView’s model to an item of a Loader and then destructing it causes the application to crash.

PRECONDITIONS:

SailfishOS installed

STEPS TO REPRODUCE:

  1. Run a QML application like this (either by making an actual application, or by saving the code in a QML file and running it using qmlscene /path/to/file.qml):
import QtQuick 2.0
import Sailfish.Silica 1.0

ApplicationWindow {
	initialPage: Component {
		Page {
			Component {
				id: page2
				Page {
					Loader {
						id: modelLoader
						sourceComponent: Component {
							ListModel {
								ListElement {name: 1}
								ListElement {name: 2}
								ListElement {name: 3}
							}
						}
					}
					PagedView {
						anchors.fill: parent
						model: modelLoader.item
						delegate: Component {
							Label {
								text: name
							}
						}
					}
				}
			}

			Timer {
				id: timer
				interval: 0
				onTriggered: pageStack.push(page2)
				running: true
			}
		}
	}
}
  1. Run the code snipper and wait for the application window to load
  2. Try to close the newly opened page with PagedView

EXPECTED RESULT:

The page is closed, PagedView instance is destructed successfully and the application continues to run.

ACTUAL RESULT:

Application crashes

MODIFICATIONS:

Patchmanager (no silica-related patches), openrepos, chum

ADDITIONAL INFORMATION:

A possible workaround is to put the model Loader inside the PagedView instance, making it the Loader’s parent.

Not an expert in QML, but your example seems weird in places…

Why is almost everything in your example a Component, including the Page’s only child?

Why do you need a Loader for the model? Is the real (non-example) model so big?

What’s the purpose of a Timer with interval 0?

  1. This can be placed in a separate file instead, but for this example I put the second page in a Component for simplicity.
  2. The real example’s model is indeed bigger, and the file allows to replace it with your own custom model via a property, in which case the model doesn’t need to be loaded
  3. Placing a call to pageStack.push in Component.onCompleted will not open the page and instead show an error saying “Cannot push while operation push in progress”

im also not that QML expert, but i had good experiences with asking a LLM for specific errors on that. Maybe you try this as well?

Thanks, but I’ve already found a workaround, please read the additional information section in the original post for that. I’m reporting a bug, not asking for help.

1 Like