[Qt-qml] QML models and components.

Martin Jones martin.jones at nokia.com
Mon Jul 19 01:49:04 CEST 2010


On Sat, 17 Jul 2010 06:03:55 am ext Lars Kinnunen wrote:
>  Hi, I am trying to understand how QML models and components work, while
> trying to understand demo code, I ran into this problem. I am wondering
> how it is supposed to work. console message is supposed to return 100,
> but it returns 0, where is the glitch?

You have not actually defined a path.  PathAttribute assigns a value at a 
particular point on the path.  If there is no path defined PathAttribute can 
have no effect.

>  And as a bonus, how do I get First_Child to show.

stackItem is the item that the view will layout.  The Text element was 
parented to the Package.  Moving the Text element to be a child of "stackItem" 
will make the text display.

I wonder why you are using Package.  In the code below there is no need to use 
it at all since each package defines only one item.  I've attached a modified 
version that defines a path and removes Package.

Martin.

> 
>  BR, Lars
> 
> -----------------------------------------------------------
> import Qt 4.7
> 
> Rectangle {
>   id: mainWindow
>   width: 200; height: 100;
>   VisualDataModel {
>     id: mainVisualModel;
>     model: ListModel {
>       id: mainModel
>       ListElement { name: "First" }
>     }
>     delegate: Component {
>       id: mainDelegate;
>       Package {
>         Item {
>           Package.name: 'overview';
>           Text { text: name; anchors.fill: parent; }
>           VisualDataModel {
>             id: childvisualModel;
>             delegate: Package {
>               id: childDelegate;
>               Item {
>                 id: stackItem
>                 Package.name: 'stack'
>                 z: stackItem.PathView.z
>               }
>               Text { text: name; anchors.fill: parent; }
>               Component.onCompleted: {
>                 console.log("Error Test == "+stackItem.PathView.z)
>               }
>             }
>             model: ListModel {
>               id: childModel
>               ListElement { name: "First_Child" }
>             }
>           }
>           PathView {
>             id: mainpathview;
>             anchors.fill: parent;
>             model: childvisualModel.parts.stack;
>             pathItemCount: 3
>             path: Path {
>               PathAttribute {
>                 name: 'z';
>                 value: 100.0
>               }
>             }
>           }
>         }
>       }
>     }
>   }
>   ListView {
>     anchors.fill: parent;
>     model: mainVisualModel.parts.overview;
>     interactive: true
>   }
> }
> 
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml

-- 
Martin
-------------- next part --------------
import Qt 4.7

Rectangle {
    id: mainWindow
    width: 200; height: 100;
    VisualDataModel {
        id: mainVisualModel;
        model: ListModel {
            id: mainModel
            ListElement { name: "First" }
        }
        delegate: Component {
            id: mainDelegate;
            Item {
                Text { text: name; anchors.fill: parent; }
                VisualDataModel {
                    id: childvisualModel;
                    delegate: Item {
                        id: stackItem
                        z: stackItem.PathView.z
                        Text { text: name; anchors.fill: parent; }
                        Component.onCompleted: {
                            console.log("Error Test == "+stackItem.PathView.z)
                        }
                    }
                    model: ListModel {
                        id: childModel
                        ListElement { name: "First_Child" }
                    }
                }
                PathView {
                    id: mainpathview;
                    anchors.fill: parent;
                    model: childvisualModel
                    pathItemCount: 3
                    path: Path {
                        startX: 100; startY: 0
                        PathAttribute {
                            name: 'z';
                            value: 100.0
                        }
                        PathLine { x: 150; y: 0 }
                    }
                }
            }
        }
    }
    ListView {
        anchors.fill: parent;
        model: mainVisualModel
        interactive: true
    }
}


More information about the Qt-qml mailing list