⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Creating dynamic QML component with complicated data type failed

  • Hello everyone.
    I am developing small application using QML.
    I've learnt from tutorial that we can create QML object dynamically via Qt.createComponent() and Component.createObject(). I am trying to implement however under certain circumstance these methods failed.
    Here are my little code:
    @// Block.qml
    id: block
    property list<url> imageSources;

    @var Block = Qt.createComponent( "Block.qml" );
    var block = Block.createObject( parent );@

    The console output: QQmlComponent: Component is not ready

    I guess it is because I use complicated data type not basic types.
    I wonder how you solve this confusing problem?
    Thanks in advance.

  • Are you sure Block.qml is a valid QML file?

  • [quote author="t3685" date="1398755036"]Are you sure Block.qml is a valid QML file?[/quote]
    To make it easy understanding, all the other properties are omitted. The symbol "……" is "not listing, irrelevant" mark.

  • Hi,

    @property list<url> imageSources;@

    does not work with my Qt 5.2.1 that's why I was asking.

  • [quote author="t3685" date="1398763566"]Hi,

    @property list<url> imageSources;@

    does not work with my Qt 5.2.1 that's why I was asking.[/quote]

    Oh, sorry to misinterpret your answer.
    Perhaps it is an invalid usage.

    The problem occurs when I replace the above code into:
    @property Block friend@

    When I run this script, the application freezes.

  • Maybe a first step is to make sure you can use Block.qml, ie. that @Block{}@ works.

  • Also there are other ways of creating dynamic objects, you can create an component like this:
    Component {
    id: blockComponent
    Block {}
    in theory that should be the same as
    var blockComponent = Qt.createComponent( "Block.qml" );
    only as an QML object and not a local variable.

    the advantage is you can simply define default values or anything in the Block object, but still create dynamic objects with the ID (you should not use a first capital letter for variable names and IDs):
    var block = blockComponent.createObject(parent);

Log in to reply