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