Working example of ListView and FolderListModel? Or: what's wrong with this code?
-
I'm trying to implement a directory browser in QML. I found and read the examples that use FolderListModel. The model seems to work. However, the ListView doesn't respond to selection. Its currentIndex never changes. The behavior is the same on my N9 and on the emulator. I am perhaps overlooking something obvious. Can one of you please tell me what's wrong with this code?
@
// MainPage.qml
import QtQuick 1.1
import com.nokia.meego 1.0
import Qt.labs.folderlistmodel 1.0Page {
tools: commonToolsListView { id: listView anchors.fill: parent clip: true delegate: fileDelegate focus: true highlight: Rectangle { color: "lightsteelblue"; radius: 5 } model: folderModel FolderListModel { id: folderModel folder: "file:///" showDirs: true showDotAndDotDot: true sortField: "Name" } Component { id: fileDelegate Text { font.family: "Nokia Pure Text" font.pixelSize: 24 text: fileName } } onCurrentIndexChanged: { console.debug("listView currentIndex:", currentIndex) } }
}
@@
// main.qml
import QtQuick 1.1
import com.nokia.meego 1.0PageStackWindow {
id: appWindowinitialPage: mainPage MainPage { id: mainPage } ToolBarLayout { id: commonTools visible: true ToolIcon { platformIconId: "toolbar-view-menu" anchors.right: (parent === undefined) ? undefined : parent.right onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close() } } Menu { id: myMenu visualParent: pageStack MenuLayout { MenuItem { text: qsTr("Quit"); onClicked: Qt.quit() } } }
}
@