2 * Copyright (C) 2016 The Qt Company Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <QQmlContext>
18 #include <QtCore/QCommandLineParser>
19 #include <QtGui/QGuiApplication>
20 #include <QtQml/QQmlContext>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQuickControls2/QQuickStyle>
23 #include <QtQuick/QQuickWindow>
24 #include <QtCore/QDir>
26 #include "eventhandler.h"
29 int main(int argc, char *argv[])
31 qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
32 qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true"));
33 QGuiApplication app(argc, argv);
34 app.setApplicationName("onstestapp");
35 app.setApplicationVersion(QStringLiteral("3.99.3"));
36 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
37 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
39 QQuickStyle::setStyle("AGL");
41 QCommandLineParser parser;
42 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
43 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
44 parser.addHelpOption();
45 parser.addVersionOption();
47 QStringList positionalArguments = parser.positionalArguments();
49 QQmlApplicationEngine engine;
52 if (positionalArguments.length() == 2) {
53 port = positionalArguments.takeFirst().toInt();
54 secret = positionalArguments.takeFirst();
57 EventHandler *eventHandler = new EventHandler();
58 eventHandler->init(port, secret.toStdString().c_str());
59 engine.rootContext()->setContextProperty("eventHandler", eventHandler);
60 QString qmldir = QCoreApplication::applicationDirPath();
61 qmldir.replace(QString("bin"), QString("qml"));
63 qDebug() << "####qmldir=" << qmldir;
64 engine.rootContext()->setContextProperty("qmldir", qmldir);
66 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
67 if (engine.rootObjects().isEmpty()) {
68 HMI_DEBUG(APP_ID, "Fatal Error, rootObject is empty!");
71 qDebug() << "####" << QDir::currentPath() << QCoreApplication::applicationDirPath();
73 QObject *root = engine.rootObjects().first();
74 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
75 QObject::connect(eventHandler, SIGNAL(signalOnReplyShowWindow(QVariant)), window, SLOT(qmlOnReplyShowWindow(QVariant)));
76 eventHandler->setQuickWindow(window);