[SOLVED] QML DefaultProperty, setting order



  • According to "this":http://qt-project.org/doc/qt-5.0/qtquick/qml-referenceexamples-default.html example:

    bq. The default property specifies the property to assign to whenever an explicit property is not specified, in the case of the BirthdayParty element the guest property. It is purely a syntactic simplification, the behavior is identical to specifying the property by name, but it can add a more natural feel in many situations. The default property must be either an object or list property.

    However, in my case behavior is different: for instance, I have GUI elements that are sensitive to an order in which they are instantiated. So if I explicitly fill my default-property list, childs are in front of parent, and in case I declare children with simle syntax - parent item becomes in front. Which actually means that latter way children were instantiated before parent, and former way children were created after parent was.
    Is that a desired behavior?

    P.S. Ofc I will fix my GUI any way, it is now in WIP state (parents aren't set in backend level), that is why I found an issue. So slease dont tell me how I solve this, I only want to know about property behavior.



  • Hmm, that is interesting. I would always expect the parent to be instantiated first (although the instantiation would not complete until the children had been instantiated and their instantiation had completed).

    Either way, the documentation is correct, so this is probably a bug. Please file it, with a simplified example which shows the issue.

    I do wonder whether the engine implements the "simple syntax" instantiations as a series of list-append operations, and the "well-defined syntax" instantiation as a single list-set operation... I don't remember the specifics, to be honest.

    Cheers,
    Chris.



  • I have re-checked the case with a clear project and came to the idea that my observations were dependent on what I do when properties of an object are being set. That last time I had a sistem which automatically sets up a GUI element onWindowChanged (for that object) event if it is possible (new window is fine).
    So what really depends on simple/well syntax is which properties of parent object are set first. I suppose with simple-syntax the default property is resolved and set first of all, when using well-syntax results in properties resolved in order they appear in QML description.
    @// 1:
    Image
    {
    window: system.graphic
    ButtonSilver { x: 20; y: 170; }
    }
    // 2:
    Image
    {
    window: system.graphic
    content: [ ButtonSilver { x: 20; y: 170; } ]
    }@

    With option "1" I've got "content" property for Image resolved and set first, and then "window" was set, resulting in gui-Image backend instantiated later then it was done for a button backend. Hence option "2" provides more kind of expected order, which however shouldn't matter as QML is declarative language. It is up to me to make my plugin as declarative as QML expects.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.