Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qml/main.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | - | |||||||||||||||||||
18 | - | |||||||||||||||||||
19 | - | |||||||||||||||||||
20 | static Config *conf = nullptr; | - | ||||||||||||||||||
21 | static QQmlApplicationEngine *qae = nullptr; | - | ||||||||||||||||||
22 | - | |||||||||||||||||||
23 | static int exitTimerId = -1; | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | bool verboseMode = false; | - | ||||||||||||||||||
26 | - | |||||||||||||||||||
27 | static void loadConf(const QString &override, bool quiet) | - | ||||||||||||||||||
28 | { | - | ||||||||||||||||||
29 | const QString defaultFileName = QLatin1String("configuration.qml"); | - | ||||||||||||||||||
30 | QUrl settingsUrl; | - | ||||||||||||||||||
31 | bool builtIn = false; | - | ||||||||||||||||||
32 | if (override.
| 0 | ||||||||||||||||||
33 | QFileInfo fi; | - | ||||||||||||||||||
34 | fi.setFile(QStandardPaths::locate(QStandardPaths::DataLocation, defaultFileName)); | - | ||||||||||||||||||
35 | if (fi.exists()
| 0 | ||||||||||||||||||
36 | settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); | - | ||||||||||||||||||
37 | } never executed: else {end of block | 0 | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | settingsUrl = QUrl(QLatin1String("qrc:///qt-project.org/QmlRuntime/conf/") + defaultFileName); | - | ||||||||||||||||||
40 | builtIn = true; | - | ||||||||||||||||||
41 | } never executed: end of block | 0 | ||||||||||||||||||
42 | } else { | - | ||||||||||||||||||
43 | QFileInfo fi; | - | ||||||||||||||||||
44 | fi.setFile(override); | - | ||||||||||||||||||
45 | if (!fi.exists()
| 0 | ||||||||||||||||||
46 | printf("qml: Couldn't find required configuration file: %s\n", | - | ||||||||||||||||||
47 | QtPrivate::asString(QDir::toNativeSeparators(fi.absoluteFilePath())).toLocal8Bit().constData()); | - | ||||||||||||||||||
48 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||
49 | } | - | ||||||||||||||||||
50 | settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); | - | ||||||||||||||||||
51 | } never executed: end of block | 0 | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | if (!quiet
| 0 | ||||||||||||||||||
54 | printf("qml: %s\n", QLibraryInfo::build()); | - | ||||||||||||||||||
55 | if (builtIn
| 0 | ||||||||||||||||||
56 | printf("qml: Using built-in configuration.\n"); never executed: printf("qml: Using built-in configuration.\n"); | 0 | ||||||||||||||||||
57 | else | - | ||||||||||||||||||
58 | printf("qml: Using configuration file: %s\n", never executed: printf("qml: Using configuration file: %s\n", QtPrivate::asString(settingsUrl.isLocalFile() ? QDir::toNativeSeparators(settingsUrl.toLocalFile()) : settingsUrl.toString()).toLocal8Bit().constData() ); | 0 | ||||||||||||||||||
59 | QtPrivate::asString(settingsUrl.isLocalFile() ? QDir::toNativeSeparators(settingsUrl.toLocalFile()) : settingsUrl.toString()).toLocal8Bit().constData() never executed: printf("qml: Using configuration file: %s\n", QtPrivate::asString(settingsUrl.isLocalFile() ? QDir::toNativeSeparators(settingsUrl.toLocalFile()) : settingsUrl.toString()).toLocal8Bit().constData() ); | 0 | ||||||||||||||||||
60 | 0 | |||||||||||||||||||
61 | ); never executed: printf("qml: Using configuration file: %s\n", QtPrivate::asString(settingsUrl.isLocalFile() ? QDir::toNativeSeparators(settingsUrl.toLocalFile()) : settingsUrl.toString()).toLocal8Bit().constData() ); | 0 | ||||||||||||||||||
62 | } | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | - | |||||||||||||||||||
65 | QQmlEngine e2; | - | ||||||||||||||||||
66 | QQmlComponent c2(&e2, settingsUrl); | - | ||||||||||||||||||
67 | conf = qobject_cast<Config*>(c2.create()); | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | if (!conf
| 0 | ||||||||||||||||||
70 | printf("qml: Error loading configuration file: %s\n", QtPrivate::asString(c2.errorString()).toLocal8Bit().constData()); | - | ||||||||||||||||||
71 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||
72 | } | - | ||||||||||||||||||
73 | } never executed: end of block | 0 | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | - | |||||||||||||||||||
76 | - | |||||||||||||||||||
77 | void noFilesGiven(); | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | - | |||||||||||||||||||
80 | class LoaderApplication : public QGuiApplication | - | ||||||||||||||||||
81 | { | - | ||||||||||||||||||
82 | public: | - | ||||||||||||||||||
83 | LoaderApplication(int& argc, char **argv) : QGuiApplication(argc, argv) {} never executed: end of block | 0 | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | bool event(QEvent *ev) override | - | ||||||||||||||||||
86 | { | - | ||||||||||||||||||
87 | if (ev->type() == QEvent::FileOpen
| 0 | ||||||||||||||||||
88 | if (exitTimerId >= 0
| 0 | ||||||||||||||||||
89 | killTimer(exitTimerId); | - | ||||||||||||||||||
90 | exitTimerId = -1; | - | ||||||||||||||||||
91 | } never executed: end of block | 0 | ||||||||||||||||||
92 | qae->load(static_cast<QFileOpenEvent *>(ev)->url()); | - | ||||||||||||||||||
93 | } never executed: end of block | 0 | ||||||||||||||||||
94 | else | - | ||||||||||||||||||
95 | return never executed: QGuiApplication::event(ev);return QGuiApplication::event(ev); never executed: return QGuiApplication::event(ev); | 0 | ||||||||||||||||||
96 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | void timerEvent(QTimerEvent *) override { | - | ||||||||||||||||||
100 | noFilesGiven(); | - | ||||||||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||||||||
102 | }; | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | - | |||||||||||||||||||
105 | - | |||||||||||||||||||
106 | - | |||||||||||||||||||
107 | class LoadWatcher : public QObject | - | ||||||||||||||||||
108 | { | - | ||||||||||||||||||
109 | public: | - | ||||||||||||||||||
110 | #pragma GCC diagnostic push | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | #pragma GCC diagnostic ignored "-Wsuggest-override" | - | ||||||||||||||||||
113 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: | - | ||||||||||||||||||
114 | #pragma GCC diagnostic ignored "-Wattributes" | - | ||||||||||||||||||
115 | __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||||||||
116 | #pragma GCC diagnostic pop | - | ||||||||||||||||||
117 | struct QPrivateSignal {}; | - | ||||||||||||||||||
118 | public: | - | ||||||||||||||||||
119 | LoadWatcher(QQmlApplicationEngine *e, int expected) | - | ||||||||||||||||||
120 | : QObject(e) | - | ||||||||||||||||||
121 | , earlyExit(false) | - | ||||||||||||||||||
122 | , returnCode(0) | - | ||||||||||||||||||
123 | , expect(expected) | - | ||||||||||||||||||
124 | , haveOne(false) | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | connect(e, qFlagLocation("2""objectCreated(QObject*,QUrl)" "\0" __FILE__ ":" "172"), | - | ||||||||||||||||||
127 | this, qFlagLocation("1""checkFinished(QObject*)" "\0" __FILE__ ":" "173")); | - | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | - | |||||||||||||||||||
130 | - | |||||||||||||||||||
131 | connect(e, qFlagLocation("2""quit()" "\0" __FILE__ ":" "177"), | - | ||||||||||||||||||
132 | this, qFlagLocation("1""quit()" "\0" __FILE__ ":" "178")); | - | ||||||||||||||||||
133 | connect(e, &QQmlEngine::exit, | - | ||||||||||||||||||
134 | this, &LoadWatcher::exit); | - | ||||||||||||||||||
135 | } never executed: end of block | 0 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | bool earlyExit; | - | ||||||||||||||||||
138 | int returnCode; | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | private: | - | ||||||||||||||||||
141 | void contain(QObject *o, const QUrl &containPath); | - | ||||||||||||||||||
142 | void checkForWindow(QObject *o); | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | int expect; | - | ||||||||||||||||||
145 | bool haveOne; | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | public : | - | ||||||||||||||||||
148 | void checkFinished(QObject *o) | - | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | if (o
| 0 | ||||||||||||||||||
151 | checkForWindow(o); | - | ||||||||||||||||||
152 | haveOne = true; | - | ||||||||||||||||||
153 | if (conf
| 0 | ||||||||||||||||||
154 | for (PartialScene *ps : qAsConst(conf->completers)) | - | ||||||||||||||||||
155 | if (o->inherits(ps->itemType().toUtf8().constData())
| 0 | ||||||||||||||||||
156 | contain(o, ps->container()); never executed: contain(o, ps->container()); | 0 | ||||||||||||||||||
157 | } never executed: end of block | 0 | ||||||||||||||||||
158 | if (haveOne
| 0 | ||||||||||||||||||
159 | return; never executed: return; | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | if (! --expect
| 0 | ||||||||||||||||||
162 | printf("qml: Did not load any objects, exiting.\n"); | - | ||||||||||||||||||
163 | std::exit(2); | - | ||||||||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||||||||
165 | } never executed: end of block | 0 | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | void quit() { | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | earlyExit = true; | - | ||||||||||||||||||
170 | returnCode = 0; | - | ||||||||||||||||||
171 | } never executed: end of block | 0 | ||||||||||||||||||
172 | void exit(int retCode) { | - | ||||||||||||||||||
173 | earlyExit = true; | - | ||||||||||||||||||
174 | returnCode = retCode; | - | ||||||||||||||||||
175 | } never executed: end of block | 0 | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | - | |||||||||||||||||||
178 | void onOpenGlContextCreated(QOpenGLContext *context); | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | }; | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | void LoadWatcher::contain(QObject *o, const QUrl &containPath) | - | ||||||||||||||||||
183 | { | - | ||||||||||||||||||
184 | QQmlComponent c(qae, containPath); | - | ||||||||||||||||||
185 | QObject *o2 = c.create(); | - | ||||||||||||||||||
186 | if (!o2
| 0 | ||||||||||||||||||
187 | return; never executed: return; | 0 | ||||||||||||||||||
188 | checkForWindow(o2); | - | ||||||||||||||||||
189 | bool success = false; | - | ||||||||||||||||||
190 | int idx; | - | ||||||||||||||||||
191 | if ((
| 0 | ||||||||||||||||||
192 | success = o2->metaObject()->property(idx).write(o2, QVariant::fromValue<QObject*>(o)); never executed: success = o2->metaObject()->property(idx).write(o2, QVariant::fromValue<QObject*>(o)); | 0 | ||||||||||||||||||
193 | if (!success
| 0 | ||||||||||||||||||
194 | o->setParent(o2); never executed: o->setParent(o2); | 0 | ||||||||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | void LoadWatcher::checkForWindow(QObject *o) | - | ||||||||||||||||||
198 | { | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | if (verboseMode
| 0 | ||||||||||||||||||
201 | connect(o, qFlagLocation("2""openglContextCreated(QOpenGLContext*)" "\0" __FILE__ ":" "247"), | - | ||||||||||||||||||
202 | this, qFlagLocation("1""onOpenGlContextCreated(QOpenGLContext*)" "\0" __FILE__ ":" "248")); | - | ||||||||||||||||||
203 | } never executed: end of block | 0 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | - | |||||||||||||||||||
206 | - | |||||||||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | - | |||||||||||||||||||
210 | void LoadWatcher::onOpenGlContextCreated(QOpenGLContext *context) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | context->makeCurrent(qobject_cast<QWindow *>(sender())); | - | ||||||||||||||||||
213 | QOpenGLFunctions functions(context); | - | ||||||||||||||||||
214 | QByteArray output = "Vendor : "; | - | ||||||||||||||||||
215 | output += reinterpret_cast<const char *>(functions.glGetString( | - | ||||||||||||||||||
216 | 0x1F00 | - | ||||||||||||||||||
217 | )); | - | ||||||||||||||||||
218 | output += "\nRenderer: "; | - | ||||||||||||||||||
219 | output += reinterpret_cast<const char *>(functions.glGetString( | - | ||||||||||||||||||
220 | 0x1F01 | - | ||||||||||||||||||
221 | )); | - | ||||||||||||||||||
222 | output += "\nVersion : "; | - | ||||||||||||||||||
223 | output += reinterpret_cast<const char *>(functions.glGetString( | - | ||||||||||||||||||
224 | 0x1F02 | - | ||||||||||||||||||
225 | )); | - | ||||||||||||||||||
226 | output += "\nLanguage: "; | - | ||||||||||||||||||
227 | output += reinterpret_cast<const char *>(functions.glGetString(0x8B8C)); | - | ||||||||||||||||||
228 | puts(output.constData()); | - | ||||||||||||||||||
229 | context->doneCurrent(); | - | ||||||||||||||||||
230 | } never executed: end of block | 0 | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | void quietMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, const QString &msg) | - | ||||||||||||||||||
234 | { | - | ||||||||||||||||||
235 | (void)ctxt;; | - | ||||||||||||||||||
236 | (void)msg;; | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | switch (type) { | - | ||||||||||||||||||
239 | case never executed: QtFatalMsg:case QtFatalMsg: never executed: case QtFatalMsg: | 0 | ||||||||||||||||||
240 | exit(-1); never executed: exit(-1); | 0 | ||||||||||||||||||
241 | case never executed: QtCriticalMsg:case QtCriticalMsg: never executed: case QtCriticalMsg: code before this statement never executed: case QtCriticalMsg: | 0 | ||||||||||||||||||
242 | case never executed: QtDebugMsg:case QtDebugMsg: never executed: case QtDebugMsg: | 0 | ||||||||||||||||||
243 | case never executed: QtWarningMsg:case QtWarningMsg: never executed: case QtWarningMsg: | 0 | ||||||||||||||||||
244 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
245 | ; | - | ||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||
247 | } | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | - | |||||||||||||||||||
250 | - | |||||||||||||||||||
251 | enum QmlApplicationType { | - | ||||||||||||||||||
252 | QmlApplicationTypeUnknown | - | ||||||||||||||||||
253 | , QmlApplicationTypeCore | - | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | , QmlApplicationTypeGui | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | , QmlApplicationTypeWidget | - | ||||||||||||||||||
258 | - | |||||||||||||||||||
259 | - | |||||||||||||||||||
260 | }; | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | - | |||||||||||||||||||
263 | - | |||||||||||||||||||
264 | - | |||||||||||||||||||
265 | QmlApplicationType applicationType = QmlApplicationTypeGui; | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | bool quietMode = false; | - | ||||||||||||||||||
268 | void printVersion() | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | printf("qml binary version "); | - | ||||||||||||||||||
271 | printf("1.1"); | - | ||||||||||||||||||
272 | printf("\nbuilt with Qt version "); | - | ||||||||||||||||||
273 | printf("5.12.0"); | - | ||||||||||||||||||
274 | printf("\n"); | - | ||||||||||||||||||
275 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||
276 | } | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | void printUsage() | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | printf("Usage: qml [options] [files] [-- args]\n"); | - | ||||||||||||||||||
281 | printf("\n"); | - | ||||||||||||||||||
282 | printf("Any unknown argument before '--' will be treated as a QML file to be loaded.\n"); | - | ||||||||||||||||||
283 | printf("Any number of QML files can be loaded. They will share the same engine.\n"); | - | ||||||||||||||||||
284 | printf("'gui' application type is only available if the QtGui module is available.\n"); | - | ||||||||||||||||||
285 | printf("'widget' application type is only available if the QtWidgets module is available.\n"); | - | ||||||||||||||||||
286 | printf("\n"); | - | ||||||||||||||||||
287 | printf("General Options:\n"); | - | ||||||||||||||||||
288 | printf("\t-h, -help..................... Print this usage information and exit.\n"); | - | ||||||||||||||||||
289 | printf("\t-v, -version.................. Print the version information and exit.\n"); | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | - | |||||||||||||||||||
292 | - | |||||||||||||||||||
293 | - | |||||||||||||||||||
294 | printf("\t-apptype [core|gui|widget] ... Select which application class to use. Default is gui.\n"); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | - | |||||||||||||||||||
297 | printf("\t-quiet ....................... Suppress all output.\n"); | - | ||||||||||||||||||
298 | printf("\t-I [path] .................... Prepend the given path to the import paths.\n"); | - | ||||||||||||||||||
299 | printf("\t-f [file] .................... Load the given file as a QML file.\n"); | - | ||||||||||||||||||
300 | printf("\t-config [file] ............... Load the given file as the configuration file.\n"); | - | ||||||||||||||||||
301 | printf("\t-- ........................... Arguments after this one are ignored by the launcher, but may be used within the QML application.\n"); | - | ||||||||||||||||||
302 | printf("\tGL options:\n"); | - | ||||||||||||||||||
303 | printf("\t-desktop.......................Force use of desktop GL (AA_UseDesktopOpenGL)\n"); | - | ||||||||||||||||||
304 | printf("\t-gles..........................Force use of GLES (AA_UseOpenGLES)\n"); | - | ||||||||||||||||||
305 | printf("\t-software......................Force use of software rendering (AA_UseOpenGLES)\n"); | - | ||||||||||||||||||
306 | printf("\t-scaling.......................Enable High DPI scaling (AA_EnableHighDpiScaling)\n"); | - | ||||||||||||||||||
307 | printf("\t-no-scaling....................Disable High DPI scaling (AA_DisableHighDpiScaling)\n"); | - | ||||||||||||||||||
308 | printf("\tDebugging options:\n"); | - | ||||||||||||||||||
309 | printf("\t-verbose ..................... Print information about what qml is doing, like specific file urls being loaded.\n"); | - | ||||||||||||||||||
310 | printf("\t-translation [file] .......... Load the given file as the translations file.\n"); | - | ||||||||||||||||||
311 | printf("\t-dummy-data [directory] ...... Load QML files from the given directory as context properties.\n"); | - | ||||||||||||||||||
312 | printf("\t-slow-animations ............. Run all animations in slow motion.\n"); | - | ||||||||||||||||||
313 | printf("\t-fixed-animations ............ Run animations off animation tick rather than wall time.\n"); | - | ||||||||||||||||||
314 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||
315 | } | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | void noFilesGiven() | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | if (!quietMode
| 0 | ||||||||||||||||||
320 | printf("qml: No files specified. Terminating.\n"); never executed: printf("qml: No files specified. Terminating.\n"); | 0 | ||||||||||||||||||
321 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | - | |||||||||||||||||||
325 | void getAppFlags(int &argc, char **argv) | - | ||||||||||||||||||
326 | { | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | for (int i=0; i<argc
| 0 | ||||||||||||||||||
329 | if (!strcmp(argv[i], "-apptype")
| 0 | ||||||||||||||||||
330 | applicationType = QmlApplicationTypeUnknown; | - | ||||||||||||||||||
331 | if (i+1 < argc
| 0 | ||||||||||||||||||
332 | if (!strcmp(argv[i+1], "core")
| 0 | ||||||||||||||||||
333 | applicationType = QmlApplicationTypeCore; never executed: applicationType = QmlApplicationTypeCore; | 0 | ||||||||||||||||||
334 | else if (!strcmp(argv[i+1], "gui")
| 0 | ||||||||||||||||||
335 | applicationType = QmlApplicationTypeGui; never executed: applicationType = QmlApplicationTypeGui; | 0 | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | else if (!strcmp(argv[i+1], "widget")
| 0 | ||||||||||||||||||
338 | applicationType = QmlApplicationTypeWidget; never executed: applicationType = QmlApplicationTypeWidget; | 0 | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | } never executed: end of block | 0 | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | if (applicationType == QmlApplicationTypeUnknown
| 0 | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | - | |||||||||||||||||||
345 | - | |||||||||||||||||||
346 | printf("-apptype must be followed by one of the following: core gui widget\n"); | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | printUsage(); | - | ||||||||||||||||||
349 | } never executed: end of block | 0 | ||||||||||||||||||
350 | for (int j=i; j<argc-2
| 0 | ||||||||||||||||||
351 | argv[j] = argv[j+2]; never executed: argv[j] = argv[j+2]; | 0 | ||||||||||||||||||
352 | argc -= 2; | - | ||||||||||||||||||
353 | } never executed: end of block | 0 | ||||||||||||||||||
354 | } never executed: end of block | 0 | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | - | |||||||||||||||||||
357 | - | |||||||||||||||||||
358 | - | |||||||||||||||||||
359 | } never executed: end of block | 0 | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | bool getFileSansBangLine(const QString &path, QByteArray &output) | - | ||||||||||||||||||
362 | { | - | ||||||||||||||||||
363 | QFile f(path); | - | ||||||||||||||||||
364 | if (!f.open(QFile::ReadOnly | QFile::Text)
| 0 | ||||||||||||||||||
365 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
366 | output = f.readAll(); | - | ||||||||||||||||||
367 | if (output.startsWith("#!")
| 0 | ||||||||||||||||||
368 | output.remove(0, output.indexOf('\n')); | - | ||||||||||||||||||
369 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
372 | } | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) | - | ||||||||||||||||||
375 | { | - | ||||||||||||||||||
376 | QDir dir(directory+"/dummydata", "*.qml"); | - | ||||||||||||||||||
377 | QStringList list = dir.entryList(); | - | ||||||||||||||||||
378 | for (int i = 0; i < list.size()
| 0 | ||||||||||||||||||
379 | QString qml = list.at(i); | - | ||||||||||||||||||
380 | QQmlComponent comp(&engine, dir.filePath(qml)); | - | ||||||||||||||||||
381 | QObject *dummyData = comp.create(); | - | ||||||||||||||||||
382 | - | |||||||||||||||||||
383 | if (comp.isError()
| 0 | ||||||||||||||||||
384 | const QList<QQmlError> errors = comp.errors(); | - | ||||||||||||||||||
385 | for (const QQmlError &error : errors) | - | ||||||||||||||||||
386 | QMessageLogger(__FILE__, 426, __PRETTY_FUNCTION__).warning() << error; never executed: QMessageLogger(__FILE__, 426, __PRETTY_FUNCTION__).warning() << error; | 0 | ||||||||||||||||||
387 | } never executed: end of block | 0 | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | if (dummyData
| 0 | ||||||||||||||||||
390 | printf("qml: Loaded dummy data: %s\n", QtPrivate::asString(dir.filePath(qml)).toLocal8Bit().constData()); | - | ||||||||||||||||||
391 | qml.truncate(qml.length()-4); | - | ||||||||||||||||||
392 | engine.rootContext()->setContextProperty(qml, dummyData); | - | ||||||||||||||||||
393 | dummyData->setParent(&engine); | - | ||||||||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||||||||
395 | } never executed: end of block | 0 | ||||||||||||||||||
396 | } never executed: end of block | 0 | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | int main(int argc, char *argv[]) | - | ||||||||||||||||||
399 | { | - | ||||||||||||||||||
400 | getAppFlags(argc, argv); | - | ||||||||||||||||||
401 | QCoreApplication *app = nullptr; | - | ||||||||||||||||||
402 | switch (applicationType) { | - | ||||||||||||||||||
403 | case never executed: QmlApplicationTypeCore:case QmlApplicationTypeCore: never executed: case QmlApplicationTypeCore: | 0 | ||||||||||||||||||
404 | app = new QCoreApplication(argc, argv); | - | ||||||||||||||||||
405 | break; never executed: break; | 0 | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | case never executed: QmlApplicationTypeGui:case QmlApplicationTypeGui: never executed: case QmlApplicationTypeGui: | 0 | ||||||||||||||||||
408 | app = new LoaderApplication(argc, argv); | - | ||||||||||||||||||
409 | break; never executed: break; | 0 | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | case never executed: QmlApplicationTypeWidget:case QmlApplicationTypeWidget: never executed: case QmlApplicationTypeWidget: | 0 | ||||||||||||||||||
412 | app = new QApplication(argc, argv); | - | ||||||||||||||||||
413 | break; never executed: break; | 0 | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | - | |||||||||||||||||||
416 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
417 | ((false) ? static_cast<void>(0) : qt_assert_x(__PRETTY_FUNCTION__, "impossible case", __FILE__, 457)); | - | ||||||||||||||||||
418 | break; never executed: break; | 0 | ||||||||||||||||||
419 | } | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | app->setApplicationName("Qml Runtime"); | - | ||||||||||||||||||
422 | app->setOrganizationName("QtProject"); | - | ||||||||||||||||||
423 | app->setOrganizationDomain("qt-project.org"); | - | ||||||||||||||||||
424 | QCoreApplication::setApplicationVersion(QLatin1String("5.12.0")); | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | qmlRegisterType<Config>("QmlRuntime.Config", 1, 0, "Configuration"); | - | ||||||||||||||||||
427 | qmlRegisterType<PartialScene>("QmlRuntime.Config", 1, 0, "PartialScene"); | - | ||||||||||||||||||
428 | QQmlApplicationEngine e; | - | ||||||||||||||||||
429 | QStringList files; | - | ||||||||||||||||||
430 | QString confFile; | - | ||||||||||||||||||
431 | QString translationFile; | - | ||||||||||||||||||
432 | QString dummyDir; | - | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | - | |||||||||||||||||||
435 | const QStringList argList = app->arguments(); | - | ||||||||||||||||||
436 | for (int i = 1; i < argList.count()
| 0 | ||||||||||||||||||
437 | const QString &arg = argList[i]; | - | ||||||||||||||||||
438 | if (arg == QLatin1String("-quiet")
| 0 | ||||||||||||||||||
439 | quietMode = true; never executed: quietMode = true; | 0 | ||||||||||||||||||
440 | else if (arg == QLatin1String("-v")
| 0 | ||||||||||||||||||
441 | printVersion(); never executed: printVersion(); | 0 | ||||||||||||||||||
442 | else if (arg == QLatin1String("-h")
| 0 | ||||||||||||||||||
443 | printUsage(); never executed: printUsage(); | 0 | ||||||||||||||||||
444 | else if (arg == QLatin1String("--")
| 0 | ||||||||||||||||||
445 | break; never executed: break; | 0 | ||||||||||||||||||
446 | else if (arg == QLatin1String("-verbose")
| 0 | ||||||||||||||||||
447 | verboseMode = true; never executed: verboseMode = true; | 0 | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | else if (arg == QLatin1String("-slow-animations")
| 0 | ||||||||||||||||||
450 | QUnifiedTimer::instance()->setSlowModeEnabled(true); never executed: QUnifiedTimer::instance()->setSlowModeEnabled(true); | 0 | ||||||||||||||||||
451 | else if (arg == QLatin1String("-fixed-animations")
| 0 | ||||||||||||||||||
452 | QUnifiedTimer::instance()->setConsistentTiming(true); never executed: QUnifiedTimer::instance()->setConsistentTiming(true); | 0 | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | else if (arg == QLatin1String("-I")
| 0 | ||||||||||||||||||
455 | if (i+1 == argList.count()
| 0 | ||||||||||||||||||
456 | continue; never executed: continue; | 0 | ||||||||||||||||||
457 | e.addImportPath(argList[i+1]); | - | ||||||||||||||||||
458 | i++; | - | ||||||||||||||||||
459 | } never executed: else if (arg == QLatin1String("-f")end of block
| 0 | ||||||||||||||||||
460 | if (i+1 == argList.count()
| 0 | ||||||||||||||||||
461 | continue; never executed: continue; | 0 | ||||||||||||||||||
462 | files << argList[i+1]; | - | ||||||||||||||||||
463 | i++; | - | ||||||||||||||||||
464 | } never executed: else if (arg == QLatin1String("-config")end of block
| 0 | ||||||||||||||||||
465 | if (i+1 == argList.count()
| 0 | ||||||||||||||||||
466 | continue; never executed: continue; | 0 | ||||||||||||||||||
467 | confFile = argList[i+1]; | - | ||||||||||||||||||
468 | i++; | - | ||||||||||||||||||
469 | } never executed: else if (arg == QLatin1String("-translation")end of block
| 0 | ||||||||||||||||||
470 | if (i+1 == argList.count()
| 0 | ||||||||||||||||||
471 | continue; never executed: continue; | 0 | ||||||||||||||||||
472 | translationFile = argList[i+1]; | - | ||||||||||||||||||
473 | i++; | - | ||||||||||||||||||
474 | } never executed: else if (arg == QLatin1String("-dummy-data")end of block
| 0 | ||||||||||||||||||
475 | if (i+1 == argList.count()
| 0 | ||||||||||||||||||
476 | continue; never executed: continue; | 0 | ||||||||||||||||||
477 | dummyDir = argList[i+1]; | - | ||||||||||||||||||
478 | i++; | - | ||||||||||||||||||
479 | } never executed: else if (arg == QLatin1String("-gles")end of block
| 0 | ||||||||||||||||||
480 | QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); | - | ||||||||||||||||||
481 | } never executed: else if (arg == QLatin1String("-software")end of block
| 0 | ||||||||||||||||||
482 | QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); | - | ||||||||||||||||||
483 | } never executed: else if (arg == QLatin1String("-desktop")end of block
| 0 | ||||||||||||||||||
484 | QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); | - | ||||||||||||||||||
485 | } never executed: else if (arg == QLatin1String("-scaling")end of block
| 0 | ||||||||||||||||||
486 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | - | ||||||||||||||||||
487 | } never executed: else if (arg == QLatin1String("-no-scaling")end of block
| 0 | ||||||||||||||||||
488 | QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); | - | ||||||||||||||||||
489 | } never executed: else {end of block | 0 | ||||||||||||||||||
490 | files << arg; | - | ||||||||||||||||||
491 | } never executed: end of block | 0 | ||||||||||||||||||
492 | } | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | if (quietMode
| 0 | ||||||||||||||||||
495 | verboseMode = false; never executed: verboseMode = false; | 0 | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | - | |||||||||||||||||||
498 | - | |||||||||||||||||||
499 | QString sysLocale = QLocale::system().name(); | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | if (!translationFile.isEmpty()
| 0 | ||||||||||||||||||
502 | QTranslator translator; | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | if (translator.load(translationFile)
| 0 | ||||||||||||||||||
505 | app->installTranslator(&translator); | - | ||||||||||||||||||
506 | if (verboseMode
| 0 | ||||||||||||||||||
507 | printf("qml: Loaded translation file %s\n", QtPrivate::asString(QDir::toNativeSeparators(translationFile)).toLocal8Bit().constData()); never executed: printf("qml: Loaded translation file %s\n", QtPrivate::asString(QDir::toNativeSeparators(translationFile)).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
508 | } never executed: else {end of block | 0 | ||||||||||||||||||
509 | if (!quietMode
| 0 | ||||||||||||||||||
510 | printf("qml: Could not load the translation file %s\n", QtPrivate::asString(QDir::toNativeSeparators(translationFile)).toLocal8Bit().constData()); never executed: printf("qml: Could not load the translation file %s\n", QtPrivate::asString(QDir::toNativeSeparators(translationFile)).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
511 | } never executed: end of block | 0 | ||||||||||||||||||
512 | } | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | - | |||||||||||||||||||
515 | - | |||||||||||||||||||
516 | - | |||||||||||||||||||
517 | - | |||||||||||||||||||
518 | if (quietMode
| 0 | ||||||||||||||||||
519 | qInstallMessageHandler(quietMessageHandler); never executed: qInstallMessageHandler(quietMessageHandler); | 0 | ||||||||||||||||||
520 | - | |||||||||||||||||||
521 | if (files.count() <= 0
| 0 | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | - | |||||||||||||||||||
524 | - | |||||||||||||||||||
525 | - | |||||||||||||||||||
526 | - | |||||||||||||||||||
527 | noFilesGiven(); | - | ||||||||||||||||||
528 | } never executed: end of block | 0 | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | qae = &e; | - | ||||||||||||||||||
531 | loadConf(confFile, !verboseMode); | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | - | |||||||||||||||||||
534 | QScopedPointer<LoadWatcher> lw(new LoadWatcher(&e, files.count())); | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | - | |||||||||||||||||||
537 | if (!dummyDir.isEmpty()
| 0 | ||||||||||||||||||
538 | loadDummyDataFiles(e, dummyDir); never executed: loadDummyDataFiles(e, dummyDir); | 0 | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | for (const QString &path : qAsConst(files)) { | - | ||||||||||||||||||
541 | QUrl url = QUrl::fromUserInput(path, QDir::currentPath(), QUrl::AssumeLocalFile); | - | ||||||||||||||||||
542 | if (verboseMode
| 0 | ||||||||||||||||||
543 | printf("qml: loading %s\n", QtPrivate::asString(url.toString()).toLocal8Bit().constData()); never executed: printf("qml: loading %s\n", QtPrivate::asString(url.toString()).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
544 | QByteArray strippedFile; | - | ||||||||||||||||||
545 | if (getFileSansBangLine(path, strippedFile)
| 0 | ||||||||||||||||||
546 | e.loadData(strippedFile, e.baseUrl().resolved(url)); never executed: e.loadData(strippedFile, e.baseUrl().resolved(url)); | 0 | ||||||||||||||||||
547 | else | - | ||||||||||||||||||
548 | e.load(url); never executed: e.load(url); | 0 | ||||||||||||||||||
549 | } | - | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | if (lw->earlyExit
| 0 | ||||||||||||||||||
552 | return never executed: lw->returnCode;return lw->returnCode; never executed: return lw->returnCode; | 0 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | return never executed: app->exec();return app->exec(); never executed: return app->exec(); | 0 | ||||||||||||||||||
555 | } | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |