Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Creating dynamic QML component with complicated data type failed
Forum Updated to NodeBB v4.3 + New Features

Creating dynamic QML component with complicated data type failed

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jiangcaiyang
    wrote on last edited by
    #1

    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
    Item
    {
    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jiangcaiyang
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          Hi,

          @property list<url> imageSources;@

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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jiangcaiyang
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              t3685
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • X Offline
                X Offline
                Xander84
                wrote on last edited by
                #7

                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);
                @

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved