[Qt-qml] QML: DataModel

Almo Nito AlmoNito at gmx.de
Mon Jul 12 23:40:33 CEST 2010


Hello There,

 

 

I played around with QML today and ended in trying on of the examples in the
docs that actually tried to use the QAbstractItemModel as a file browser.

 

So I copy-pasted the source and tried out their example with the result that
the root directory is showing up (the "/") and the onClick handler is
working as well,

 

The only problem is that it don't seems possible to brows the File system,
any ideas on that one?

 

 

 

QML:

 

 

import Qt 4.7

import "ressource" as Ressources

 

Rectangle {

    id: background

    width: 770;

    height: 480;

    color: "lightgray"

 

    ListView {

        id: view

        width: 300

        height: 400

 

 

        model: VisualDataModel {

 

            model: myModel

 

            delegate: Rectangle {

                width: 200; height: 25

                Text { text: filePath }

 

                MouseArea {

                    anchors.fill: parent

                    onClicked: {

 

 

                        if (view.model.hasModelChildren) {

                            console.log("childs")

                            view.model.rootIndex = model.modelIndex(index)

                        }

                        else {

                            console.log("NoChilds")

 

                        }

 

                    }

                }

            }

 

        }

 

    }

}

 

 

 

 

C++:

 

 

QDeclarativeView *view = new QDeclarativeView(this);

 

 

    QFileSystemModel *modelDir = new QFileSystemModel;

    modelDir->setRootPath("/home");

 

 

    ui->treeView->setModel(modelDir);

 

 

 

    QDeclarativeContext *ctxt = view->rootContext();

    ctxt->setContextProperty("myModel",modelDir);

 

 

    QUrl url = QUrl::fromLocalFile("browsertest.qml");

    view->setSource(url);

 

 

    view->show();

 

 

 

 

 

 

Further in the C++ I have anoter issue, if I set the RootDir as in
modelDir->setRootPath("/home"); it seems not to do any changes at all.

 

Any Ideas?

Thanks!

Almo

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100712/473f8323/attachment.html 


More information about the Qt-qml mailing list