b78a68a691c5aee41e51449cbad827f944b4826c
[profile/ivi/qtdeclarative.git] / tools / qmlplugindump / main.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the tools applications of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QtDeclarative/QtDeclarative>
43 #include <QtDeclarative/private/qdeclarativemetatype_p.h>
44 #include <QtDeclarative/private/qdeclarativeopenmetaobject_p.h>
45 #include <QtDeclarative/QDeclarativeView>
46
47 #include <QtGui/QApplication>
48
49 #include <QtCore/QSet>
50 #include <QtCore/QMetaObject>
51 #include <QtCore/QMetaProperty>
52 #include <QtCore/QDebug>
53 #include <QtCore/private/qobject_p.h>
54 #include <QtCore/private/qmetaobject_p.h>
55
56 #include <iostream>
57
58 #include "qmlstreamwriter.h"
59
60 #ifdef QT_SIMULATOR
61 #include <QtGui/private/qsimulatorconnection_p.h>
62 #endif
63
64 #ifdef Q_OS_UNIX
65 #include <signal.h>
66 #endif
67
68 QString pluginImportPath;
69 bool verbose = false;
70
71 QString currentProperty;
72 QString inObjectInstantiation;
73
74 void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas)
75 {
76     if (! meta || metas->contains(meta))
77         return;
78
79     // dynamic meta objects break things badly, so just ignore them
80     const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate *>(meta->d.data);
81     if (!(mop->flags & DynamicMetaObject))
82         metas->insert(meta);
83
84     collectReachableMetaObjects(meta->superClass(), metas);
85 }
86
87 void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *metas)
88 {
89     if (! object)
90         return;
91
92     const QMetaObject *meta = object->metaObject();
93     if (verbose)
94         qDebug() << "Processing object" << meta->className();
95     collectReachableMetaObjects(meta, metas);
96
97     for (int index = 0; index < meta->propertyCount(); ++index) {
98         QMetaProperty prop = meta->property(index);
99         if (QDeclarativeMetaType::isQObject(prop.userType())) {
100             if (verbose)
101                 qDebug() << "  Processing property" << prop.name();
102             currentProperty = QString("%1::%2").arg(meta->className(), prop.name());
103
104             // if the property was not initialized during construction,
105             // accessing a member of oo is going to cause a segmentation fault
106             QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object));
107             if (oo && !metas->contains(oo->metaObject()))
108                 collectReachableMetaObjects(oo, metas);
109             currentProperty.clear();
110         }
111     }
112 }
113
114 void collectReachableMetaObjects(const QDeclarativeType *ty, QSet<const QMetaObject *> *metas)
115 {
116     collectReachableMetaObjects(ty->metaObject(), metas);
117     if (ty->attachedPropertiesType())
118         collectReachableMetaObjects(ty->attachedPropertiesType(), metas);
119 }
120
121 /* We want to add the MetaObject for 'Qt' to the list, this is a
122    simple way to access it.
123 */
124 class FriendlyQObject: public QObject
125 {
126 public:
127     static const QMetaObject *qtMeta() { return &staticQtMetaObject; }
128 };
129
130 /* When we dump a QMetaObject, we want to list all the types it is exported as.
131    To do this, we need to find the QDeclarativeTypes associated with this
132    QMetaObject.
133 */
134 static QHash<QByteArray, QSet<const QDeclarativeType *> > qmlTypesByCppName;
135
136 static QHash<QByteArray, QByteArray> cppToId;
137
138 /* Takes a C++ type name, such as Qt::LayoutDirection or QString and
139    maps it to how it should appear in the description file.
140
141    These names need to be unique globally, so we don't change the C++ symbol's
142    name much. It is mostly used to for explicit translations such as
143    QString->string and translations for extended QML objects.
144 */
145 QByteArray convertToId(const QByteArray &cppName)
146 {
147     return cppToId.value(cppName, cppName);
148 }
149
150 QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode, QDeclarativeEngine *engine)
151 {
152     QSet<const QMetaObject *> metas;
153     metas.insert(FriendlyQObject::qtMeta());
154
155     QHash<QByteArray, QSet<QByteArray> > extensions;
156     foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
157         qmlTypesByCppName[ty->metaObject()->className()].insert(ty);
158         if (ty->isExtendedType()) {
159             extensions[ty->typeName()].insert(ty->metaObject()->className());
160         }
161         collectReachableMetaObjects(ty, &metas);
162     }
163
164     // Adjust exports of the base object if there are extensions.
165     // For each export of a base object there can be a single extension object overriding it.
166     // Example: QDeclarativeGraphicsWidget overrides the QtQuick/QGraphicsWidget export
167     //          of QGraphicsWidget.
168     foreach (const QByteArray &baseCpp, extensions.keys()) {
169         QSet<const QDeclarativeType *> baseExports = qmlTypesByCppName.value(baseCpp);
170
171         const QSet<QByteArray> extensionCppNames = extensions.value(baseCpp);
172         foreach (const QByteArray &extensionCppName, extensionCppNames) {
173             const QSet<const QDeclarativeType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
174
175             // remove extension exports from base imports
176             // unfortunately the QDeclarativeType pointers don't match, so can't use QSet::substract
177             QSet<const QDeclarativeType *> newBaseExports;
178             foreach (const QDeclarativeType *baseExport, baseExports) {
179                 bool match = false;
180                 foreach (const QDeclarativeType *extensionExport, extensionExports) {
181                     if (baseExport->qmlTypeName() == extensionExport->qmlTypeName()
182                             && baseExport->majorVersion() == extensionExport->majorVersion()
183                             && baseExport->minorVersion() == extensionExport->minorVersion()) {
184                         match = true;
185                         break;
186                     }
187                 }
188                 if (!match)
189                     newBaseExports.insert(baseExport);
190             }
191             baseExports = newBaseExports;
192         }
193         qmlTypesByCppName[baseCpp] = baseExports;
194     }
195
196     // find even more QMetaObjects by instantiating QML types and running
197     // over the instances
198     foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
199         if (ty->isExtendedType())
200             continue;
201         if (!ty->isCreatable())
202             continue;
203         if (ty->typeName() == "QDeclarativeComponent")
204             continue;
205
206         QByteArray tyName = ty->qmlTypeName();
207         tyName = tyName.mid(tyName.lastIndexOf('/') + 1);
208         if (tyName.isEmpty())
209             continue;
210
211         QByteArray code = importCode.toUtf8();
212         code += tyName;
213         code += " {}\n";
214
215         QDeclarativeComponent c(engine);
216         c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typeinstance.qml"));
217
218         inObjectInstantiation = tyName;
219         QObject *object = c.create();
220         inObjectInstantiation.clear();
221
222         if (object)
223             collectReachableMetaObjects(object, &metas);
224         else
225             qWarning() << "Could not create" << tyName << ":" << c.errorString();
226     }
227
228     return metas;
229 }
230
231
232 class Dumper
233 {
234     QmlStreamWriter *qml;
235     QString relocatableModuleUri;
236
237 public:
238     Dumper(QmlStreamWriter *qml) : qml(qml) {}
239
240     void setRelocatableModuleUri(const QString &uri)
241     {
242         relocatableModuleUri = uri;
243     }
244
245     void dump(const QMetaObject *meta)
246     {
247         qml->writeStartObject("Component");
248
249         QByteArray id = convertToId(meta->className());
250         qml->writeScriptBinding(QLatin1String("name"), enquote(id));
251
252         for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) {
253             QMetaClassInfo classInfo = meta->classInfo(index);
254             if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) {
255                 qml->writeScriptBinding(QLatin1String("defaultProperty"), enquote(QLatin1String(classInfo.value())));
256                 break;
257             }
258         }
259
260         if (meta->superClass())
261             qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()->className())));
262
263         QSet<const QDeclarativeType *> qmlTypes = qmlTypesByCppName.value(meta->className());
264         if (!qmlTypes.isEmpty()) {
265             QStringList exports;
266
267             foreach (const QDeclarativeType *qmlTy, qmlTypes) {
268                 QString qmlTyName = qmlTy->qmlTypeName();
269                 // some qmltype names are missing the actual names, ignore that import
270                 if (qmlTyName.endsWith('/'))
271                     continue;
272                 if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
273                     qmlTyName.remove(0, relocatableModuleUri.size() + 1);
274                 }
275                 if (qmlTyName.startsWith("./")) {
276                     qmlTyName.remove(0, 2);
277                 }
278                 exports += enquote(QString("%1 %2.%3").arg(
279                                        qmlTyName,
280                                        QString::number(qmlTy->majorVersion()),
281                                        QString::number(qmlTy->minorVersion())));
282             }
283
284             // ensure exports are sorted and don't change order when the plugin is dumped again
285             exports.removeDuplicates();
286             qSort(exports);
287
288             qml->writeArrayBinding(QLatin1String("exports"), exports);
289
290             if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) {
291                 qml->writeScriptBinding(QLatin1String("attachedType"), enquote(
292                                             convertToId(attachedType->className())));
293             }
294         }
295
296         for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index)
297             dump(meta->enumerator(index));
298
299         for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index)
300             dump(meta->property(index));
301
302         for (int index = meta->methodOffset(); index < meta->methodCount(); ++index)
303             dump(meta->method(index));
304
305         qml->writeEndObject();
306     }
307
308     void writeEasingCurve()
309     {
310         qml->writeStartObject("Component");
311         qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve")));
312         qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QDeclarativeEasingValueType")));
313         qml->writeEndObject();
314     }
315
316 private:
317     static QString enquote(const QString &string)
318     {
319         return QString("\"%1\"").arg(string);
320     }
321
322     /* Removes pointer and list annotations from a type name, returning
323        what was removed in isList and isPointer
324     */
325     static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer)
326     {
327         static QByteArray declListPrefix = "QDeclarativeListProperty<";
328
329         if (typeName->endsWith('*')) {
330             *isPointer = true;
331             typeName->truncate(typeName->length() - 1);
332             removePointerAndList(typeName, isList, isPointer);
333         } else if (typeName->startsWith(declListPrefix)) {
334             *isList = true;
335             typeName->truncate(typeName->length() - 1); // get rid of the suffix '>'
336             *typeName = typeName->mid(declListPrefix.size());
337             removePointerAndList(typeName, isList, isPointer);
338         }
339
340         *typeName = convertToId(*typeName);
341     }
342
343     void writeTypeProperties(QByteArray typeName, bool isWritable)
344     {
345         bool isList = false, isPointer = false;
346         removePointerAndList(&typeName, &isList, &isPointer);
347
348         qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
349         if (isList)
350             qml->writeScriptBinding(QLatin1String("isList"), QLatin1String("true"));
351         if (!isWritable)
352             qml->writeScriptBinding(QLatin1String("isReadonly"), QLatin1String("true"));
353         if (isPointer)
354             qml->writeScriptBinding(QLatin1String("isPointer"), QLatin1String("true"));
355     }
356
357     void dump(const QMetaProperty &prop)
358     {
359         qml->writeStartObject("Property");
360
361         qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name())));
362 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
363         if (int revision = prop.revision())
364             qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
365 #endif
366         writeTypeProperties(prop.typeName(), prop.isWritable());
367
368         qml->writeEndObject();
369     }
370
371     void dump(const QMetaMethod &meth)
372     {
373         if (meth.methodType() == QMetaMethod::Signal) {
374             if (meth.access() != QMetaMethod::Protected)
375                 return; // nothing to do.
376         } else if (meth.access() != QMetaMethod::Public) {
377             return; // nothing to do.
378         }
379
380         QByteArray name = meth.signature();
381         int lparenIndex = name.indexOf('(');
382         if (lparenIndex == -1) {
383             return; // invalid signature
384         }
385         name = name.left(lparenIndex);
386
387         if (meth.methodType() == QMetaMethod::Signal)
388             qml->writeStartObject(QLatin1String("Signal"));
389         else
390             qml->writeStartObject(QLatin1String("Method"));
391
392         qml->writeScriptBinding(QLatin1String("name"), enquote(name));
393
394 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
395         if (int revision = meth.revision())
396             qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
397 #endif
398
399         const QString typeName = convertToId(meth.typeName());
400         if (! typeName.isEmpty())
401             qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
402
403         for (int i = 0; i < meth.parameterTypes().size(); ++i) {
404             QByteArray argName = meth.parameterNames().at(i);
405
406             qml->writeStartObject(QLatin1String("Parameter"));
407             if (! argName.isEmpty())
408                 qml->writeScriptBinding(QLatin1String("name"), enquote(argName));
409             writeTypeProperties(meth.parameterTypes().at(i), true);
410             qml->writeEndObject();
411         }
412
413         qml->writeEndObject();
414     }
415
416     void dump(const QMetaEnum &e)
417     {
418         qml->writeStartObject(QLatin1String("Enum"));
419         qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name())));
420
421         QList<QPair<QString, QString> > namesValues;
422         for (int index = 0; index < e.keyCount(); ++index) {
423             namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index))));
424         }
425
426         qml->writeScriptObjectLiteralBinding(QLatin1String("values"), namesValues);
427         qml->writeEndObject();
428     }
429 };
430
431
432 enum ExitCode {
433     EXIT_INVALIDARGUMENTS = 1,
434     EXIT_SEGV = 2,
435     EXIT_IMPORTERROR = 3
436 };
437
438 #ifdef Q_OS_UNIX
439 void sigSegvHandler(int) {
440     fprintf(stderr, "Error: SEGV\n");
441     if (!currentProperty.isEmpty())
442         fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData());
443     if (!inObjectInstantiation.isEmpty())
444         fprintf(stderr, "While instantiating the object '%s'.\n", inObjectInstantiation.toLatin1().constData());
445     exit(EXIT_SEGV);
446 }
447 #endif
448
449 void printUsage(const QString &appName)
450 {
451     qWarning() << qPrintable(QString(
452                                  "Usage: %1 [-v] [-notrelocatable] module.uri version [module/import/path]\n"
453                                  "       %1 [-v] -path path/to/qmldir/directory [version]\n"
454                                  "       %1 [-v] -builtins\n"
455                                  "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg(
456                                  appName));
457 }
458
459 int main(int argc, char *argv[])
460 {
461 #ifdef Q_OS_UNIX
462     // qmldump may crash, but we don't want any crash handlers to pop up
463     // therefore we intercept the segfault and just exit() ourselves
464     struct sigaction sigAction;
465
466     sigemptyset(&sigAction.sa_mask);
467     sigAction.sa_handler = &sigSegvHandler;
468     sigAction.sa_flags   = 0;
469
470     sigaction(SIGSEGV, &sigAction, 0);
471 #endif
472
473 #ifdef QT_SIMULATOR
474     // Running this application would bring up the Qt Simulator (since it links QtGui), avoid that!
475     QtSimulatorPrivate::SimulatorConnection::createStubInstance();
476 #endif
477     QApplication app(argc, argv);
478     const QStringList args = app.arguments();
479     const QString appName = QFileInfo(app.applicationFilePath()).baseName();
480     if (args.size() < 2) {
481         printUsage(appName);
482         return EXIT_INVALIDARGUMENTS;
483     }
484
485     QString pluginImportUri;
486     QString pluginImportVersion;
487     bool relocatable = true;
488     enum Action { Uri, Path, Builtins };
489     Action action = Uri;
490     {
491         QStringList positionalArgs;
492         foreach (const QString &arg, args) {
493             if (!arg.startsWith(QLatin1Char('-'))) {
494                 positionalArgs.append(arg);
495                 continue;
496             }
497
498             if (arg == QLatin1String("--notrelocatable")
499                     || arg == QLatin1String("-notrelocatable")) {
500                 relocatable = false;
501             } else if (arg == QLatin1String("--path")
502                        || arg == QLatin1String("-path")) {
503                 action = Path;
504             } else if (arg == QLatin1String("--builtins")
505                        || arg == QLatin1String("-builtins")) {
506                 action = Builtins;
507             } else if (arg == QLatin1String("-v")) {
508                 verbose = true;
509             } else {
510                 qWarning() << "Invalid argument: " << arg;
511                 return EXIT_INVALIDARGUMENTS;
512             }
513         }
514
515         if (action == Uri) {
516             if (positionalArgs.size() != 3 && positionalArgs.size() != 4) {
517                 qWarning() << "Incorrect number of positional arguments";
518                 return EXIT_INVALIDARGUMENTS;
519             }
520             pluginImportUri = positionalArgs[1];
521             pluginImportVersion = positionalArgs[2];
522             if (positionalArgs.size() >= 4)
523                 pluginImportPath = positionalArgs[3];
524         } else if (action == Path) {
525             if (positionalArgs.size() != 2 && positionalArgs.size() != 3) {
526                 qWarning() << "Incorrect number of positional arguments";
527                 return EXIT_INVALIDARGUMENTS;
528             }
529             pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]);
530             if (positionalArgs.size() == 3)
531                 pluginImportVersion = positionalArgs[2];
532         } else if (action == Builtins) {
533             if (positionalArgs.size() != 1) {
534                 qWarning() << "Incorrect number of positional arguments";
535                 return EXIT_INVALIDARGUMENTS;
536             }
537         }
538     }
539
540     QDeclarativeView view;
541     QDeclarativeEngine *engine = view.engine();
542     if (!pluginImportPath.isEmpty()) {
543         QDir cur = QDir::current();
544         cur.cd(pluginImportPath);
545         pluginImportPath = cur.absolutePath();
546         QDir::setCurrent(pluginImportPath);
547         engine->addImportPath(pluginImportPath);
548     }
549
550     // find all QMetaObjects reachable from the builtin module
551     QByteArray importCode("import QtQuick 2.0\n");
552     QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(importCode, engine);
553
554     // this will hold the meta objects we want to dump information of
555     QSet<const QMetaObject *> metas;
556
557     if (action == Builtins) {
558         metas = defaultReachable;
559     } else {
560         // find all QMetaObjects reachable when the specified module is imported
561         if (action != Path) {
562             importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii();
563         } else {
564             // pluginImportVersion can be empty
565             importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toAscii();
566         }
567
568         // create a component with these imports to make sure the imports are valid
569         // and to populate the declarative meta type system
570         {
571             QByteArray code = importCode;
572             code += "QtObject {}";
573             QDeclarativeComponent c(engine);
574
575             c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml"));
576             c.create();
577             if (!c.errors().isEmpty()) {
578                 foreach (const QDeclarativeError &error, c.errors())
579                     qWarning() << error.toString();
580                 return EXIT_IMPORTERROR;
581             }
582         }
583
584         QSet<const QMetaObject *> candidates = collectReachableMetaObjects(importCode, engine);
585         candidates.subtract(defaultReachable);
586
587         // Also eliminate meta objects with the same classname.
588         // This is required because extended objects seem not to share
589         // a single meta object instance.
590         QSet<QByteArray> defaultReachableNames;
591         foreach (const QMetaObject *mo, defaultReachable)
592             defaultReachableNames.insert(QByteArray(mo->className()));
593         foreach (const QMetaObject *mo, candidates) {
594             if (!defaultReachableNames.contains(mo->className()))
595                 metas.insert(mo);
596         }
597     }
598
599     // setup static rewrites of type names
600     cppToId.insert("QString", "string");
601     cppToId.insert("QDeclarativeEasingValueType::Type", "Type");
602
603     // start dumping data
604     QByteArray bytes;
605     QmlStreamWriter qml(&bytes);
606
607     qml.writeStartDocument();
608     qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 1);
609     qml.write("\n"
610               "// This file describes the plugin-supplied types contained in the library.\n"
611               "// It is used for QML tooling purposes only.\n"
612               "\n");
613     qml.writeStartObject("Module");
614
615     // put the metaobjects into a map so they are always dumped in the same order
616     QMap<QString, const QMetaObject *> nameToMeta;
617     foreach (const QMetaObject *meta, metas)
618         nameToMeta.insert(convertToId(meta->className()), meta);
619
620     Dumper dumper(&qml);
621     if (relocatable)
622         dumper.setRelocatableModuleUri(pluginImportUri);
623     foreach (const QMetaObject *meta, nameToMeta) {
624         dumper.dump(meta);
625     }
626
627     // define QEasingCurve as an extension of QDeclarativeEasingValueType, this way
628     // properties using the QEasingCurve type get useful type information.
629     if (pluginImportUri.isEmpty())
630         dumper.writeEasingCurve();
631
632     qml.writeEndObject();
633     qml.writeEndDocument();
634
635     std::cout << bytes.constData();
636
637     // workaround to avoid crashes on exit
638     QTimer timer;
639     timer.setSingleShot(true);
640     timer.setInterval(0);
641     QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit()));
642     timer.start();
643
644     return app.exec();
645 }