diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-04-28 07:35:59 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-04-28 23:53:30 (GMT) |
commit | fd7c1acef4bd3b1aa4b160592af140bd87c21829 (patch) | |
tree | f6dcd506df1d0dbcef5ed386557f24036ccf244e /doc/src/snippets/declarative | |
parent | f8f87a70993eaed6de9bd7c614663282e8d80e46 (diff) | |
download | Qt-fd7c1acef4bd3b1aa4b160592af140bd87c21829.zip Qt-fd7c1acef4bd3b1aa4b160592af140bd87c21829.tar.gz Qt-fd7c1acef4bd3b1aa4b160592af140bd87c21829.tar.bz2 |
Fix references to createComponent() and createQmlObject() to
Qt.createComponent() and Qt.createQmlObject(). Also move code into
snippets/ for verification.
Diffstat (limited to 'doc/src/snippets/declarative')
-rw-r--r-- | doc/src/snippets/declarative/Sprite.qml | 3 | ||||
-rw-r--r-- | doc/src/snippets/declarative/componentCreation.js | 57 | ||||
-rw-r--r-- | doc/src/snippets/declarative/createComponent.qml | 9 | ||||
-rw-r--r-- | doc/src/snippets/declarative/createQmlObject.qml | 18 |
4 files changed, 87 insertions, 0 deletions
diff --git a/doc/src/snippets/declarative/Sprite.qml b/doc/src/snippets/declarative/Sprite.qml new file mode 100644 index 0000000..6670703 --- /dev/null +++ b/doc/src/snippets/declarative/Sprite.qml @@ -0,0 +1,3 @@ +import Qt 4.7 + +Rectangle { width: 80; height: 50; color: "red" } diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js new file mode 100644 index 0000000..be3e4d6 --- /dev/null +++ b/doc/src/snippets/declarative/componentCreation.js @@ -0,0 +1,57 @@ +//![0] +var component; +var sprite; + +function finishCreation() { + if (component.isReady) { + sprite = component.createObject(); + if (sprite == null) { + // Error Handling + } else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... + } + } else if (component.isError()) { + // Error Handling + console.log("Error loading component:", component.errorsString()); + } +} +//![0] + +//![1] +function createSpriteObjects() { +//![1] + + //![2] + component = Qt.createComponent("Sprite.qml"); + if (component.isReady) + finishCreation(); + else + component.statusChanged.connect(finishCreation); + //![2] + + //![3] + component = Qt.createComponent("Sprite.qml"); + sprite = component.createObject(); + + if (sprite == null) { + // Error Handling + console.log("Error loading component:", component.errorsString()); + } else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... + } + //![3] + +//![4] +} +//![4] + +//![5] +createSpriteObjects(); +//![5] + diff --git a/doc/src/snippets/declarative/createComponent.qml b/doc/src/snippets/declarative/createComponent.qml new file mode 100644 index 0000000..c4a1617 --- /dev/null +++ b/doc/src/snippets/declarative/createComponent.qml @@ -0,0 +1,9 @@ +import Qt 4.7 +import "componentCreation.js" as MyModule + +Rectangle { + id: appWindow + width: 300; height: 300 + + Component.onCompleted: MyModule.createSpriteObjects(); +} diff --git a/doc/src/snippets/declarative/createQmlObject.qml b/doc/src/snippets/declarative/createQmlObject.qml new file mode 100644 index 0000000..6b331c4 --- /dev/null +++ b/doc/src/snippets/declarative/createQmlObject.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + id: targetItem + property QtObject newObject + + width: 100 + height: 100 + + function createIt() { +//![0] +newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', + targetItem, "dynamicSnippet1"); +//![0] + } + + Component.onCompleted: createIt() +} |