YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include <QtGui/QGuiApplication>
7#include "qtquick2applicationviewer.h"
8#include "config.h"
9
10#include <csignal>
11
12#include <QQmlApplicationEngine>
13#include <QQuickWindow>
14#include <QtWidgets/QApplication>
15#include <QQmlContext>
16#include <QVariant>
17#include <QDir>
18#include <QtGlobal>
19
20void catchSignals(int sig) {
21 // blocking and not aysnc-signal-safe func are valid
22 printf("\nYarpview killed by signal(%d).\n", sig);
23 QCoreApplication::quit();
24}
25
31int main(int argc, char *argv[])
32{
33 bool minimal=false;
34 bool compact=false;
35 bool keepabove=false;
36 // Pack the argc and argv to a QStringList so we can pass them easily to
37 // the plugin.
38 // This list must be packed before creating the QApplication, because
39 // QApplication will remove the known arguments, and this includes the
40 // "--name <name>" argument on linux.
41 QStringList params;
42 for(int i=1;i<argc;i++){
43 params.append(argv[i]);
44 if (std::string(argv[i]) == "--compact")
45 {
46 compact=true;
47 }
48 if (std::string(argv[i]) == "--minimal")
49 {
50 minimal=true;
51 }
52 if (std::string(argv[i]) == "--keep-above")
53 {
54 keepabove=true;
55 }
56 }
57
58#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
59 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
60#else
61 qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("auto"));
62#endif
63 QApplication app(argc, argv);
64 // add SIGINT and SIGTERM handler
65 std::signal(SIGINT, catchSignals);
66 std::signal(SIGTERM, catchSignals);
67
68#if !defined(_WIN32)
69 std::signal(SIGQUIT, catchSignals);
70 std::signal(SIGHUP, catchSignals);
71#endif
72
73 QVariant retVal;
74
75 // De-comment this to trace all imports
76 /*QByteArray data = "1";
77 qputenv("QML_IMPORT_TRACE", data);*/
78
79 QQmlApplicationEngine engine;
80 engine.addImportPath(QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() +
81 PLUGINS_RELATIVE_PATH));
82#ifdef CMAKE_INTDIR
83 engine.addImportPath(QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() +
84 ".." + QDir::separator() +
85 PLUGINS_RELATIVE_PATH + QDir::separator() +
86 CMAKE_INTDIR));
87#endif
88 if (compact || minimal)
89 {
90 engine.load(QUrl("qrc:/qml/QtYARPView/mainCompact.qml"));
91 }
92 else
93 {
94 engine.load(QUrl("qrc:/qml/QtYARPView/main.qml"));
95 }
96
97 QObject *topLevel = engine.rootObjects().value(0);
98
99 if(!topLevel){
100 return 1;
101 }
102
103 auto* window = qobject_cast<QQuickWindow *>(topLevel);
104 if (minimal)
105 {
106 window->setFlags(Qt::FramelessWindowHint);
107 }
108 if (keepabove)
109 {
110 window->setFlags(Qt::WindowStaysOnTopHint);
111 }
112
113 // Call the parseParameters of the qml object called YARPVideoSurface
114 auto* yarpVideoSurface = topLevel->findChild<QObject*>("YARPVideoSurface");
115 QMetaObject::invokeMethod(yarpVideoSurface,"parseParameters",
116 Qt::DirectConnection,
117 Q_RETURN_ARG(QVariant, retVal),
118 Q_ARG(QVariant,params));
119 if(!retVal.toBool()){
120 return 1;
121 }
122
123 window->show();
124 window->setIcon(QIcon(":/logo.png"));
125 // window->setIcon(QIcon(":/logo.svg"));
126
127 return (app.exec()!=0?1:0);
128}
int main(int argc, char *argv[])
Definition main.cpp:385
void catchSignals(int sig)
Definition main.cpp:20