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. The order of property initialization of a QML component
Forum Updated to NodeBB v4.3 + New Features

The order of property initialization of a QML component

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.0k 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.
  • benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #1

    Hi,

    Anyone knows the rule of the order of property initialization of a QML component? I am writing a GUI application with style engine that allow to change the style of a GUI component.

    For example ,

    main.qml

    @
    WidgetA {
    style.fieldA: 3
    }
    @

    WidgetA.qml
    @
    Rectangle {
    property StyleA style : Style.widgetAStyle ; // Style is a singleton object with default style information.
    }
    @

    StyleA.qml
    @
    QtObject {
    property int fieldA : 0;
    }
    @

    However, sometimes QML will complain : "Cannot set properties on style as it is null" in the main.qml. But sometimes it won't . So I am very confused that why the Widget.style property is not initialized when I use it. Anyone know the rule? I can't find any document talk about that.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Sorry, i don't know the rule eather, but there is a QML Analysis tool which you could use to check which objects were created first. You can find it on the left side of your Qt Creator directly below Projects. Just run your QML Application using this tool.

      1 Reply Last reply
      0
      • benlauB Offline
        benlauB Offline
        benlau
        Qt Champions 2016
        wrote on last edited by
        #3

        Hi onek24,

        Thanks for your reply. But how the profiler can tell you the sequence of creation? Check the timeline?

        By the way , I found a dirty hack to fix my problem:

        A widget:
        @
        property TextInputStyle style : Style.theme.textInput
        @

        That is my original code. "Style" is a singleton object shared by all widget to provide the default style information. But it will complains "Cannot set properties on style as it is null” in the main.qml for setting custom style for the instance.

        This piece of code fix the problem:

        @
        property TextInputStyle style : TextInputStyle {
        background: Style.theme.textInput.background
        textStyle: TextStyle {
        textSize: Style.theme.textInput.textStyle.textSize
        textColor: Style.theme.textInput.textStyle.textColor
        }
        textSelectHandle: Style.theme.textInput.textSelectHandle
        }
        @

        I guess one of the factor to determine the order is the "depth" of component. Nested component will go first. And simple variable assignment will go later.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          Hey benlau,

          bq. Thanks for your reply. But how the profiler can tell you the sequence of creation? Check the timeline?

          Yes, just check the timeline. it describes a lot.

          bq. I guess one of the factor to determine the order is the “depth” of component. Nested component will go first. And simple variable assignment will go later.

          I would say the same, i'll look into it if i find some time today.

          Keep us up to date if you found out something new :)

          1 Reply Last reply
          0
          • benlauB Offline
            benlauB Offline
            benlau
            Qt Champions 2016
            wrote on last edited by
            #5

            [quote author="onek24" date="1417697726"]Hey benlau,
            I would say the same, i'll look into it if i find some time today.

            Keep us up to date if you found out something new :)[/quote]

            well , It is better to let Qt developer to declare an official document about the order. Otherwise, what we did is just a dirty hack .. In fact, I have encountered the problem of initalization sequence for several times already.

            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