Solved QguiApplication crashes due to Loader
-
I am facing an crash issue when dataModel refreshes (from backend using begin /end resetmodel ) after the openpage function gets called . Anyone please tell me what could be the issue with this loader assignation.If I add the loader inside delegate it is not crashing !!!!!
Loader{
id : loadView
}Repeater{
model: dataModeldelegate: Item{ function openPage{ loadView.source="smeComp.qml" loadView.item.model = dataModel loadView.item.delegate = Qt.createComponent("smeDelegate.qml") } subDataModel{ id: dataModel } Button{ onClicked: openPage() } }
}
-
Loader loads only one qml file at a time. You are loading the multiple qml files using only loader. When the new file is loaded, old objects are deleted. Hence must be hitting the crash issue.
-
@dheerendra New file will be loaded only when I click the button again right?. That means Open page function is getting called again .In that case it is not crashing.When the model assgined to repeater is reloaded ,the crash is happening.I suspect the subDataModel assigned to loader item gets deleted but the loader referring the same.Hence it is crashing.But I don't know how to confirm the same.
-
Number of delegate objects are same as number of elements in model. However you are using only one Loader. That will give issue.
-
Yes you are correct.On demand basis (button click event) only I am creating page.If I keep the Loader inside delegate ,the page is getting closed when model is refreshing .I want to keep the page open when model is refreshing.How to achieve the same
-
found the root cause .creation context of Qt.createcomponent () inside delegates gets destroyed when model resets ,as per following rules.
The actual creation context depends on how an object is created:If Qt.createComponent() is used, the creation context is the QQmlContext in which this method is called If Qt.createQmlObject() is called, the creation context is the context of the parent object passed to this method If a Component{} object is defined and createObject() or incubateObject() is called on that object, the creation context is the context in which the Component is defined.
Solution is to move the creation context outside the delegate