summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/declarative/componentCreation.js
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/snippets/declarative/componentCreation.js')
-rw-r--r--doc/src/snippets/declarative/componentCreation.js63
1 files changed, 34 insertions, 29 deletions
diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js
index 25bc10c..c29a1f9 100644
--- a/doc/src/snippets/declarative/componentCreation.js
+++ b/doc/src/snippets/declarative/componentCreation.js
@@ -1,7 +1,39 @@
-//![0]
+//![vars]
var component;
var sprite;
+//![vars]
+//![func]
+function createSpriteObjects() {
+//![func]
+
+//![remote]
+ component = Qt.createComponent("Sprite.qml");
+ if (component.status == Component.Ready)
+ finishCreation();
+ else
+ component.statusChanged.connect(finishCreation);
+//![remote]
+
+//![local]
+ component = Qt.createComponent("Sprite.qml");
+ sprite = component.createObject(appWindow);
+
+ if (sprite == null) {
+ // Error Handling
+ console.log("Error creating object");
+ } else {
+ sprite.x = 100;
+ sprite.y = 100;
+ // ...
+ }
+//![local]
+
+//![func-end]
+}
+//![func-end]
+
+//![finishCreation]
function finishCreation() {
if (component.status == Component.Ready) {
sprite = component.createObject(appWindow);
@@ -17,31 +49,4 @@ function finishCreation() {
console.log("Error loading component:", component.errorString());
}
}
-//![0]
-
-function createSpriteObjects() {
-
-//![1]
-component = Qt.createComponent("Sprite.qml");
-if (component.status == Component.Ready)
- finishCreation();
-else
- component.statusChanged.connect(finishCreation);
-//![1]
-
-//![2]
-component = Qt.createComponent("Sprite.qml");
-sprite = component.createObject(appWindow);
-
-if (sprite == null) {
- // Error Handling
- console.log("Error loading component:", component.errorString());
-} else {
- sprite.x = 100;
- sprite.y = 100;
- // ...
-}
-//![2]
-
-}
-
+//![finishCreation]