summaryrefslogtreecommitdiffstats
path: root/examples/declarative
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2010-05-05 18:54:19 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2010-05-05 18:54:19 (GMT)
commit0a8379d9f01118d7ff0121e6ecbbc0307e1e7f63 (patch)
treedbbf96df4245ecd37d9c9f0b619afaf6ddd19e38 /examples/declarative
parent337dbd5391b4e2b1bd88918a46f3392df8fd1312 (diff)
downloadQt-0a8379d9f01118d7ff0121e6ecbbc0307e1e7f63.zip
Qt-0a8379d9f01118d7ff0121e6ecbbc0307e1e7f63.tar.gz
Qt-0a8379d9f01118d7ff0121e6ecbbc0307e1e7f63.tar.bz2
Make component.createObject require a parent argument
For graphical objects (the common case) a common mistake is to not parent a dynamically created item. Since you almost always want to add a parent, and it's hard for a beginner to diagnose this problem, a parent is now a required argument and dealt with by the createObject function. Task-number: QTBUG-10110
Diffstat (limited to 'examples/declarative')
-rw-r--r--examples/declarative/dynamic/qml/itemCreation.js3
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.js3
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/samegame.js3
-rwxr-xr-xexamples/declarative/tutorials/samegame/samegame4/content/samegame.js3
4 files changed, 4 insertions, 8 deletions
diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js
index 3c1b975..08f5320 100644
--- a/examples/declarative/dynamic/qml/itemCreation.js
+++ b/examples/declarative/dynamic/qml/itemCreation.js
@@ -42,8 +42,7 @@ function loadComponent() {
function createItem() {
if (itemComponent.status == Component.Ready && draggedItem == null) {
- draggedItem = itemComponent.createObject();
- draggedItem.parent = window;
+ draggedItem = itemComponent.createObject(window);
draggedItem.image = itemButton.image;
draggedItem.x = xOffset;
draggedItem.y = yOffset;
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js
index bcfb5b6..0dbe6a6 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js
@@ -41,13 +41,12 @@ function createBlock(column, row) {
// Loading and we should wait for the component's statusChanged() signal to
// know when the file is downloaded and ready before calling createObject().
if (component.status == Component.Ready) {
- var dynamicObject = component.createObject();
+ var dynamicObject = component.createObject(background);
if (dynamicObject == null) {
console.log("error creating block");
console.log(component.errorsString());
return false;
}
- dynamicObject.parent = background;
dynamicObject.x = column * blockSize;
dynamicObject.y = row * blockSize;
dynamicObject.width = blockSize;
diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js
index 4256aee..e5ba6e0 100644
--- a/examples/declarative/tutorials/samegame/samegame3/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js
@@ -38,14 +38,13 @@ function createBlock(column, row) {
// Loading and we should wait for the component's statusChanged() signal to
// know when the file is downloaded and ready before calling createObject().
if (component.status == Component.Ready) {
- var dynamicObject = component.createObject();
+ var dynamicObject = component.createObject(gameCanvas);
if (dynamicObject == null) {
console.log("error creating block");
console.log(component.errorsString());
return false;
}
dynamicObject.type = Math.floor(Math.random() * 3);
- dynamicObject.parent = gameCanvas;
dynamicObject.x = column * gameCanvas.blockSize;
dynamicObject.y = row * gameCanvas.blockSize;
dynamicObject.width = gameCanvas.blockSize;
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
index 961cd66..159c9a7 100755
--- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
@@ -49,14 +49,13 @@ function createBlock(column, row) {
// Loading and we should wait for the component's statusChanged() signal to
// know when the file is downloaded and ready before calling createObject().
if (component.status == Component.Ready) {
- var dynamicObject = component.createObject();
+ var dynamicObject = component.createObject(gameCanvas);
if (dynamicObject == null) {
console.log("error creating block");
console.log(component.errorsString());
return false;
}
dynamicObject.type = Math.floor(Math.random() * 3);
- dynamicObject.parent = gameCanvas;
dynamicObject.x = column * gameCanvas.blockSize;
dynamicObject.targetX = column * gameCanvas.blockSize;
dynamicObject.targetY = row * gameCanvas.blockSize;