summaryrefslogtreecommitdiffstats
path: root/examples/demos/addressbook/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/demos/addressbook/main.cpp')
-rw-r--r--examples/demos/addressbook/main.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/demos/addressbook/main.cpp b/examples/demos/addressbook/main.cpp
new file mode 100644
index 000000000..f419e5b36
--- /dev/null
+++ b/examples/demos/addressbook/main.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "addressbookmodel.h"
+#include "restaccessmanager.h"
+
+#include <QCommandLineParser>
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QQmlContext>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QCommandLineParser parser;
+ parser.addOptions({
+ { "host", QCoreApplication::translate("main", "Hostname of the server."), "host" },
+ { "port", QCoreApplication::translate("main", "Port of the server."), "port" },
+ });
+ parser.addHelpOption();
+ parser.process(app);
+
+ if (parser.value("host").isEmpty() || parser.value("port").isEmpty())
+ parser.showHelp(-1);
+
+ QQmlApplicationEngine engine;
+ auto manager = QSharedPointer<RestAccessManager>::create(parser.value("host"),
+ parser.value("port").toInt());
+ AddressBookModel model(manager);
+ engine.setInitialProperties({ { "addressBookModel", QVariant::fromValue(&model) } });
+
+ engine.load(QUrl("qrc:/qml/main.qml"));
+ if (engine.rootObjects().isEmpty())
+ return -1;
+
+ return QGuiApplication::exec();
+}