Hi
I study example form site: http://doc.qt.io/qt-5/qtqml-javascri...tcreation.html
It is about dynamic objects creation. Notable part of this article is following example:
var component;
var sprite;
function createSpriteObjects() {
component = Qt.createComponent("Sprite.qml");
if (component.status == Component.Ready)
finishCreation();
else
component.statusChanged.connect(finishCreation);
}
function finishCreation() {
if (component.status == Component.Ready) {
sprite = component.createObject(appWindow, {"x": 100, "y": 100});
if (sprite == null) {
// Error Handling
console.log("Error creating object");
}
} else if (component.status == Component.Error) {
// Error Handling
console.log("Error loading component:", component.errorString());
}
}
var component;
var sprite;
function createSpriteObjects() {
component = Qt.createComponent("Sprite.qml");
if (component.status == Component.Ready)
finishCreation();
else
component.statusChanged.connect(finishCreation);
}
function finishCreation() {
if (component.status == Component.Ready) {
sprite = component.createObject(appWindow, {"x": 100, "y": 100});
if (sprite == null) {
// Error Handling
console.log("Error creating object");
}
} else if (component.status == Component.Error) {
// Error Handling
console.log("Error loading component:", component.errorString());
}
}
To copy to clipboard, switch view to plain text mode
It (optionally) splits object creation to 2 parts. It is clear that object maybe created in a bit lengthy period of time, so to avoid app freezing it returns and fire signal when ready.
In my opinion the problem with first line in quoted example:
var component;
var component;
To copy to clipboard, switch view to plain text mode
What if I will create another object bertween exit createSpriteObjects() and before call finishCreation()?!? It is protected some how?!? It is impossible?!?
I think it is race! Most often it will works, but some day it will crash silently...
What is your opinion of the subject?!?
thanks and best regards
Szyk Cech
Bookmarks