summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/quick/controls/filesystembrowser/main.cpp10
-rw-r--r--examples/quick/controls/filesystembrowser/main.qml6
2 files changed, 13 insertions, 3 deletions
diff --git a/examples/quick/controls/filesystembrowser/main.cpp b/examples/quick/controls/filesystembrowser/main.cpp
index 1322bc49..ac24bada 100644
--- a/examples/quick/controls/filesystembrowser/main.cpp
+++ b/examples/quick/controls/filesystembrowser/main.cpp
@@ -88,16 +88,18 @@ static inline QString sizeString(const QFileInfo &fi)
}
class DisplayFileSystemModel : public QFileSystemModel {
+ Q_OBJECT
public:
explicit DisplayFileSystemModel(QObject *parent = Q_NULLPTR)
: QFileSystemModel(parent) {}
- enum {
+ enum Roles {
SizeRole = Qt::UserRole + 4,
DisplayableFilePermissionsRole = Qt::UserRole + 5,
LastModifiedRole = Qt::UserRole + 6,
- UrlStringRole = Qt::UserRole + 7 // 263
+ UrlStringRole = Qt::UserRole + 7
};
+ Q_ENUM(Roles)
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE
{
@@ -133,6 +135,8 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QQmlApplicationEngine engine;
+ qmlRegisterUncreatableType<DisplayFileSystemModel>("io.qt.examples.quick.controls.filesystembrowser", 1, 0,
+ "FileSystemModel", "Cannot create a FileSystemModel instance.");
QFileSystemModel *fsm = new DisplayFileSystemModel(&engine);
fsm->setRootPath(QDir::homePath());
fsm->setResolveSymlinks(true);
@@ -142,3 +146,5 @@ int main(int argc, char *argv[])
return app.exec();
}
+
+#include "main.moc"
diff --git a/examples/quick/controls/filesystembrowser/main.qml b/examples/quick/controls/filesystembrowser/main.qml
index b85002d5..6e79ca61 100644
--- a/examples/quick/controls/filesystembrowser/main.qml
+++ b/examples/quick/controls/filesystembrowser/main.qml
@@ -41,6 +41,7 @@
import QtQuick 2.2
import QtQuick.Controls 1.5
import QtQml.Models 2.2
+import io.qt.examples.quick.controls.filesystembrowser 1.0
ApplicationWindow {
visible: true
@@ -120,6 +121,9 @@ ApplicationWindow {
resizable: true
}
- onActivated : Qt.openUrlExternally(fileSystemModel.data(index, 263))
+ onActivated : {
+ var url = fileSystemModel.data(index, FileSystemModel.UrlStringRole)
+ Qt.openUrlExternally(url)
+ }
}
}