2
var newObject = Qt.createQmlObject('import bb.cascades 1.0; Label {text: "Hold on cowboy!" }', parentContainer, "dynamicSnippet1");

It runs, and an object is returned, but it never shows on the screen. I have parented it to a container in my page QML. No errors are thrown. I am wondering whether this isn't functional in Cascades.

It is documented here in the BB10 Cascades documentation: https://developer.blackberry.com/cascades/reference/qml-qt.html#createQmlObject-method

dmdrummond
  • 184
  • 1
  • 7
  • me too. I use Qt 5.3.0 and it not works as expected. You can create component if you can define it in a `.qml` file. See `Qt.createComponent()` in documentation for more information. – S.M.Mousavi Jul 22 '14 at 07:44

3 Answers3

1

1) Please check whether the newObject is created or not.

Here is the sample code:

var newObject = Qt.createQmlObject('import bb.cascades 1.0; 
    Label {text: "Hold on cowboy!" }', parentContainer, "dynamicSnippet1");

if(newObject == null) {
   console.log("error creating object" +  newObject.errorString());
}

2) Please make sure that parentContainer is visible.

mariomario
  • 660
  • 1
  • 9
  • 29
1

OK, I found a problem for my case.
I used Qt.createQmlObject() as follow:

import QtQuick 2.2;

Rectangle {
    id: root
    width: 300; height: 300

    Row {
        id: itemContainer
        Component.onCompleted: {
            var newObject = Qt.createQmlObject('import QtQuick 2.2; Rectangle {color: "red"; width: 200; height: 200}', itemContainer, "");
        }

        Rectangle {
            width: 100; height: 50
            color: "Yellow"
        }
    }
}

This not works and I changed it as follow:

import QtQuick 2.2;

Rectangle {
    id: root
    width: 300; height: 300

    Row {
        id: itemContainer

        Rectangle {
            width: 100; height: 50
            color: "Yellow"
        }

        Component.onCompleted: {
            var newObject = Qt.createQmlObject('import QtQuick 2.2; Rectangle {color: "red"; width: 200; height: 200}', itemContainer, "");
        }
    }
}

and it WORKS, but not as expected! As you can see, executing Qt.createQmlObject() inside a Row element not causes to recalculation of some of essential estimations of Row element.
I reported this as bug in https://bugreports.qt-project.org/browse/QTBUG-40356

S.M.Mousavi
  • 5,013
  • 7
  • 44
  • 59
0

It looks like to me that problem is in size and/or position not given. Try this:

var newObject = Qt.createQmlObject('import bb.cascades 1.0; Label {text: "Hold on cowboy!"; anchors.fill: parent }', parentContainer, "dynamicSnippet1");

Also try parent to anchor to window size (root element - if its not already).

Another problem that might occur is that font color matches to background, so check that too.

DRAX
  • 30,559
  • 2
  • 26
  • 28