diff options
Diffstat (limited to 'examples/quick/controls/filesystembrowser/main.cpp')
-rw-r--r-- | examples/quick/controls/filesystembrowser/main.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/quick/controls/filesystembrowser/main.cpp b/examples/quick/controls/filesystembrowser/main.cpp index 176d334c..e9c63c20 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,11 +135,18 @@ 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); engine.rootContext()->setContextProperty("fileSystemModel", fsm); + engine.rootContext()->setContextProperty("rootPathIndex", fsm->index(fsm->rootPath())); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; return app.exec(); } + +#include "main.moc" |