aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/filesystemexplorer/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quickcontrols/filesystemexplorer/main.cpp')
-rw-r--r--examples/quickcontrols/filesystemexplorer/main.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/quickcontrols/filesystemexplorer/main.cpp b/examples/quickcontrols/filesystemexplorer/main.cpp
new file mode 100644
index 0000000000..9a43fa9d6d
--- /dev/null
+++ b/examples/quickcontrols/filesystemexplorer/main.cpp
@@ -0,0 +1,43 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "filesystemmodel.h"
+
+#include <QGuiApplication>
+#include <QCommandLineParser>
+#include <QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ // Initialize the static application object.
+ QGuiApplication app(argc, argv);
+ QGuiApplication::setOrganizationName("QtProject");
+ QGuiApplication::setApplicationName("File System Explorer");
+ QGuiApplication::setApplicationVersion(QT_VERSION_STR);
+ QGuiApplication::setWindowIcon(QIcon(":/qt/qml/FileSystemModule/icons/app_icon.svg"));
+
+ // Setup the parser and parse the command-line arguments.
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Qt Filesystemexplorer Example");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("", QGuiApplication::translate(
+ "main", "Initial directory"),"[path]");
+ parser.process(app);
+ const auto args = parser.positionalArguments();
+
+ // Load the QML entry point.
+ QQmlApplicationEngine engine;
+ engine.loadFromModule("FileSystemModule", "Main");
+ if (engine.rootObjects().isEmpty())
+ return -1;
+
+ // Set the initial directory if provided
+ if (args.length() == 1) {
+ auto *fileSystemModel = engine.singletonInstance<FileSystemModel*>(
+ "FileSystemModule","FileSystemModel");
+ fileSystemModel->setInitialDirectory(args[0]);
+ }
+
+ return QGuiApplication::exec(); // Start the event loop.
+}