1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the tools applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtQml/qqmlengine.h>
43 #include <QtQml/private/qqmlmetatype_p.h>
44 #include <QtQml/private/qqmlopenmetaobject_p.h>
45 #include <QtQuick/private/qquickevents_p_p.h>
46 #include <QtQuick/private/qquickpincharea_p.h>
48 #include <QtGui/QGuiApplication>
49 #include <QtCore/QDir>
50 #include <QtCore/QFileInfo>
51 #include <QtCore/QSet>
52 #include <QtCore/QStringList>
53 #include <QtCore/QTimer>
54 #include <QtCore/QMetaObject>
55 #include <QtCore/QMetaProperty>
56 #include <QtCore/QDebug>
57 #include <QtCore/private/qobject_p.h>
58 #include <QtCore/private/qmetaobject_p.h>
62 #include "qmlstreamwriter.h"
65 #include <QtGui/private/qsimulatorconnection_p.h>
72 QString pluginImportPath;
75 QString currentProperty;
76 QString inObjectInstantiation;
78 void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas, bool extended = false)
80 if (! meta || metas->contains(meta))
83 // dynamic meta objects can break things badly
84 // but extended types are usually fine
85 const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate *>(meta->d.data);
86 if (extended || !(mop->flags & DynamicMetaObject))
89 collectReachableMetaObjects(meta->superClass(), metas);
92 void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *metas)
97 const QMetaObject *meta = object->metaObject();
99 qDebug() << "Processing object" << meta->className();
100 collectReachableMetaObjects(meta, metas);
102 for (int index = 0; index < meta->propertyCount(); ++index) {
103 QMetaProperty prop = meta->property(index);
104 if (QQmlMetaType::isQObject(prop.userType())) {
106 qDebug() << " Processing property" << prop.name();
107 currentProperty = QString("%1::%2").arg(meta->className(), prop.name());
109 // if the property was not initialized during construction,
110 // accessing a member of oo is going to cause a segmentation fault
111 QObject *oo = QQmlMetaType::toQObject(prop.read(object));
112 if (oo && !metas->contains(oo->metaObject()))
113 collectReachableMetaObjects(oo, metas);
114 currentProperty.clear();
119 void collectReachableMetaObjects(const QQmlType *ty, QSet<const QMetaObject *> *metas)
121 collectReachableMetaObjects(ty->metaObject(), metas, ty->isExtendedType());
122 if (ty->attachedPropertiesType())
123 collectReachableMetaObjects(ty->attachedPropertiesType(), metas);
126 /* We want to add the MetaObject for 'Qt' to the list, this is a
127 simple way to access it.
129 class FriendlyQObject: public QObject
132 static const QMetaObject *qtMeta() { return &staticQtMetaObject; }
135 /* When we dump a QMetaObject, we want to list all the types it is exported as.
136 To do this, we need to find the QQmlTypes associated with this
139 static QHash<QByteArray, QSet<const QQmlType *> > qmlTypesByCppName;
141 static QHash<QByteArray, QByteArray> cppToId;
143 /* Takes a C++ type name, such as Qt::LayoutDirection or QString and
144 maps it to how it should appear in the description file.
146 These names need to be unique globally, so we don't change the C++ symbol's
147 name much. It is mostly used to for explicit translations such as
148 QString->string and translations for extended QML objects.
150 QByteArray convertToId(const QByteArray &cppName)
152 return cppToId.value(cppName, cppName);
155 QByteArray convertToId(const QMetaObject *mo)
157 QByteArray className(mo->className());
158 if (!className.isEmpty())
159 return convertToId(className);
161 // likely a metaobject generated for an extended qml object
162 if (mo->superClass()) {
163 className = convertToId(mo->superClass());
164 className.append("_extended");
168 static QHash<const QMetaObject *, QByteArray> generatedNames;
169 className = generatedNames.value(mo);
170 if (!className.isEmpty())
173 qWarning() << "Found a QMetaObject without a className, generating a random name";
174 className = QByteArray("error-unknown-name-");
175 className.append(QByteArray::number(generatedNames.size()));
176 generatedNames.insert(mo, className);
180 QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const QList<QQmlType *> &skip = QList<QQmlType *>())
182 QSet<const QMetaObject *> metas;
183 metas.insert(FriendlyQObject::qtMeta());
185 QHash<QByteArray, QSet<QByteArray> > extensions;
186 foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) {
187 qmlTypesByCppName[ty->metaObject()->className()].insert(ty);
188 if (ty->isExtendedType()) {
189 extensions[ty->typeName()].insert(ty->metaObject()->className());
191 collectReachableMetaObjects(ty, &metas);
194 // Adjust exports of the base object if there are extensions.
195 // For each export of a base object there can be a single extension object overriding it.
196 // Example: QDeclarativeGraphicsWidget overrides the QtQuick/QGraphicsWidget export
197 // of QGraphicsWidget.
198 foreach (const QByteArray &baseCpp, extensions.keys()) {
199 QSet<const QQmlType *> baseExports = qmlTypesByCppName.value(baseCpp);
201 const QSet<QByteArray> extensionCppNames = extensions.value(baseCpp);
202 foreach (const QByteArray &extensionCppName, extensionCppNames) {
203 const QSet<const QQmlType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
205 // remove extension exports from base imports
206 // unfortunately the QQmlType pointers don't match, so can't use QSet::substract
207 QSet<const QQmlType *> newBaseExports;
208 foreach (const QQmlType *baseExport, baseExports) {
210 foreach (const QQmlType *extensionExport, extensionExports) {
211 if (baseExport->qmlTypeName() == extensionExport->qmlTypeName()
212 && baseExport->majorVersion() == extensionExport->majorVersion()
213 && baseExport->minorVersion() == extensionExport->minorVersion()) {
219 newBaseExports.insert(baseExport);
221 baseExports = newBaseExports;
223 qmlTypesByCppName[baseCpp] = baseExports;
226 // find even more QMetaObjects by instantiating QML types and running
227 // over the instances
228 foreach (QQmlType *ty, QQmlMetaType::qmlTypes()) {
229 if (skip.contains(ty))
231 if (ty->isExtendedType())
233 if (!ty->isCreatable())
235 if (ty->typeName() == "QQmlComponent")
238 QString tyName = ty->qmlTypeName();
239 tyName = tyName.mid(tyName.lastIndexOf(QLatin1Char('/')) + 1);
240 if (tyName.isEmpty())
243 inObjectInstantiation = tyName;
246 if (ty->isSingleton()) {
247 QQmlType::SingletonInstanceInfo *siinfo = ty->singletonInstanceInfo();
248 if (siinfo->qobjectCallback) {
249 siinfo->init(engine);
250 collectReachableMetaObjects(object, &metas);
251 object = siinfo->qobjectApi(engine);
253 inObjectInstantiation.clear();
254 continue; // we don't handle QJSValue singleton types.
260 inObjectInstantiation.clear();
263 collectReachableMetaObjects(object, &metas);
265 qWarning() << "Could not create" << tyName;
274 QmlStreamWriter *qml;
275 QString relocatableModuleUri;
278 Dumper(QmlStreamWriter *qml) : qml(qml) {}
280 void setRelocatableModuleUri(const QString &uri)
282 relocatableModuleUri = uri;
285 void dump(const QMetaObject *meta)
287 qml->writeStartObject("Component");
289 QByteArray id = convertToId(meta);
290 qml->writeScriptBinding(QLatin1String("name"), enquote(id));
292 for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) {
293 QMetaClassInfo classInfo = meta->classInfo(index);
294 if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) {
295 qml->writeScriptBinding(QLatin1String("defaultProperty"), enquote(QLatin1String(classInfo.value())));
300 if (meta->superClass())
301 qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass())));
303 QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className());
304 if (!qmlTypes.isEmpty()) {
305 QHash<QString, const QQmlType *> exports;
307 foreach (const QQmlType *qmlTy, qmlTypes) {
308 QString qmlTyName = qmlTy->qmlTypeName();
309 if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
310 qmlTyName.remove(0, relocatableModuleUri.size() + 1);
312 if (qmlTyName.startsWith("./")) {
313 qmlTyName.remove(0, 2);
315 if (qmlTyName.startsWith("/")) {
316 qmlTyName.remove(0, 1);
318 const QString exportString = enquote(
319 QString("%1 %2.%3").arg(
321 QString::number(qmlTy->majorVersion()),
322 QString::number(qmlTy->minorVersion())));
323 exports.insert(exportString, qmlTy);
326 // ensure exports are sorted and don't change order when the plugin is dumped again
327 QStringList exportStrings = exports.keys();
328 qSort(exportStrings);
329 qml->writeArrayBinding(QLatin1String("exports"), exportStrings);
331 // write meta object revisions unless they're all zero
332 QStringList metaObjectRevisions;
333 bool shouldWriteMetaObjectRevisions = false;
334 foreach (const QString &exportString, exportStrings) {
335 int metaObjectRevision = exports[exportString]->metaObjectRevision();
336 if (metaObjectRevision != 0)
337 shouldWriteMetaObjectRevisions = true;
338 metaObjectRevisions += QString::number(metaObjectRevision);
340 if (shouldWriteMetaObjectRevisions)
341 qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), metaObjectRevisions);
343 if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) {
344 // Can happen when a type is registered that returns itself as attachedPropertiesType()
345 // because there is no creatable type to attach to.
346 if (attachedType != meta) {
347 qml->writeScriptBinding(QLatin1String("attachedType"), enquote(
348 convertToId(attachedType)));
353 for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index)
354 dump(meta->enumerator(index));
356 QSet<QString> implicitSignals;
357 for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index) {
358 const QMetaProperty &property = meta->property(index);
360 implicitSignals.insert(QString("%1Changed").arg(QString::fromUtf8(property.name())));
363 if (meta == &QObject::staticMetaObject) {
364 // for QObject, hide deleteLater() and onDestroyed
365 for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) {
366 QMetaMethod method = meta->method(index);
367 QByteArray signature = method.methodSignature();
368 if (signature == QByteArrayLiteral("destroyed(QObject*)")
369 || signature == QByteArrayLiteral("destroyed()")
370 || signature == QByteArrayLiteral("deleteLater()"))
372 dump(method, implicitSignals);
375 // and add toString(), destroy() and destroy(int)
376 qml->writeStartObject(QLatin1String("Method"));
377 qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("toString")));
378 qml->writeEndObject();
379 qml->writeStartObject(QLatin1String("Method"));
380 qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("destroy")));
381 qml->writeEndObject();
382 qml->writeStartObject(QLatin1String("Method"));
383 qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("destroy")));
384 qml->writeStartObject(QLatin1String("Parameter"));
385 qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("delay")));
386 qml->writeScriptBinding(QLatin1String("type"), enquote(QLatin1String("int")));
387 qml->writeEndObject();
388 qml->writeEndObject();
390 for (int index = meta->methodOffset(); index < meta->methodCount(); ++index)
391 dump(meta->method(index), implicitSignals);
394 qml->writeEndObject();
397 void writeEasingCurve()
399 qml->writeStartObject(QLatin1String("Component"));
400 qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve")));
401 qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QQmlEasingValueType")));
402 qml->writeEndObject();
406 static QString enquote(const QString &string)
408 return QString("\"%1\"").arg(string);
411 /* Removes pointer and list annotations from a type name, returning
412 what was removed in isList and isPointer
414 static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer)
416 static QByteArray declListPrefix = "QQmlListProperty<";
418 if (typeName->endsWith('*')) {
420 typeName->truncate(typeName->length() - 1);
421 removePointerAndList(typeName, isList, isPointer);
422 } else if (typeName->startsWith(declListPrefix)) {
424 typeName->truncate(typeName->length() - 1); // get rid of the suffix '>'
425 *typeName = typeName->mid(declListPrefix.size());
426 removePointerAndList(typeName, isList, isPointer);
429 *typeName = convertToId(*typeName);
432 void writeTypeProperties(QByteArray typeName, bool isWritable)
434 bool isList = false, isPointer = false;
435 removePointerAndList(&typeName, &isList, &isPointer);
437 qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
439 qml->writeScriptBinding(QLatin1String("isList"), QLatin1String("true"));
441 qml->writeScriptBinding(QLatin1String("isReadonly"), QLatin1String("true"));
443 qml->writeScriptBinding(QLatin1String("isPointer"), QLatin1String("true"));
446 void dump(const QMetaProperty &prop)
448 qml->writeStartObject("Property");
450 qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name())));
451 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
452 if (int revision = prop.revision())
453 qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
455 writeTypeProperties(prop.typeName(), prop.isWritable());
457 qml->writeEndObject();
460 void dump(const QMetaMethod &meth, const QSet<QString> &implicitSignals)
462 if (meth.methodType() == QMetaMethod::Signal) {
463 if (meth.access() != QMetaMethod::Protected)
464 return; // nothing to do.
465 } else if (meth.access() != QMetaMethod::Public) {
466 return; // nothing to do.
469 QByteArray name = meth.name();
470 const QString typeName = convertToId(meth.typeName());
472 if (implicitSignals.contains(name)
474 && meth.methodType() == QMetaMethod::Signal
475 && meth.parameterNames().isEmpty()
476 && typeName.isEmpty()) {
477 // don't mention implicit signals
481 if (meth.methodType() == QMetaMethod::Signal)
482 qml->writeStartObject(QLatin1String("Signal"));
484 qml->writeStartObject(QLatin1String("Method"));
486 qml->writeScriptBinding(QLatin1String("name"), enquote(name));
488 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
489 if (int revision = meth.revision())
490 qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
493 if (! typeName.isEmpty())
494 qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
496 for (int i = 0; i < meth.parameterTypes().size(); ++i) {
497 QByteArray argName = meth.parameterNames().at(i);
499 qml->writeStartObject(QLatin1String("Parameter"));
500 if (! argName.isEmpty())
501 qml->writeScriptBinding(QLatin1String("name"), enquote(argName));
502 writeTypeProperties(meth.parameterTypes().at(i), true);
503 qml->writeEndObject();
506 qml->writeEndObject();
509 void dump(const QMetaEnum &e)
511 qml->writeStartObject(QLatin1String("Enum"));
512 qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name())));
514 QList<QPair<QString, QString> > namesValues;
515 for (int index = 0; index < e.keyCount(); ++index) {
516 namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index))));
519 qml->writeScriptObjectLiteralBinding(QLatin1String("values"), namesValues);
520 qml->writeEndObject();
526 EXIT_INVALIDARGUMENTS = 1,
532 void sigSegvHandler(int) {
533 fprintf(stderr, "Error: SEGV\n");
534 if (!currentProperty.isEmpty())
535 fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData());
536 if (!inObjectInstantiation.isEmpty())
537 fprintf(stderr, "While instantiating the object '%s'.\n", inObjectInstantiation.toLatin1().constData());
542 void printUsage(const QString &appName)
544 qWarning() << qPrintable(QString(
545 "Usage: %1 [-v] [-notrelocatable] module.uri version [module/import/path]\n"
546 " %1 [-v] -path path/to/qmldir/directory [version]\n"
547 " %1 [-v] -builtins\n"
548 "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg(
552 int main(int argc, char *argv[])
555 // qmldump may crash, but we don't want any crash handlers to pop up
556 // therefore we intercept the segfault and just exit() ourselves
557 struct sigaction sigAction;
559 sigemptyset(&sigAction.sa_mask);
560 sigAction.sa_handler = &sigSegvHandler;
561 sigAction.sa_flags = 0;
563 sigaction(SIGSEGV, &sigAction, 0);
567 // Running this application would bring up the Qt Simulator (since it links QtGui), avoid that!
568 QtSimulatorPrivate::SimulatorConnection::createStubInstance();
571 QGuiApplication app(argc, argv);
572 const QStringList args = app.arguments();
573 const QString appName = QFileInfo(app.applicationFilePath()).baseName();
574 if (args.size() < 2) {
576 return EXIT_INVALIDARGUMENTS;
579 QString pluginImportUri;
580 QString pluginImportVersion;
581 bool relocatable = true;
582 enum Action { Uri, Path, Builtins };
585 QStringList positionalArgs;
586 foreach (const QString &arg, args) {
587 if (!arg.startsWith(QLatin1Char('-'))) {
588 positionalArgs.append(arg);
592 if (arg == QLatin1String("--notrelocatable")
593 || arg == QLatin1String("-notrelocatable")) {
595 } else if (arg == QLatin1String("--path")
596 || arg == QLatin1String("-path")) {
598 } else if (arg == QLatin1String("--builtins")
599 || arg == QLatin1String("-builtins")) {
601 } else if (arg == QLatin1String("-v")) {
604 qWarning() << "Invalid argument: " << arg;
605 return EXIT_INVALIDARGUMENTS;
610 if (positionalArgs.size() != 3 && positionalArgs.size() != 4) {
611 qWarning() << "Incorrect number of positional arguments";
612 return EXIT_INVALIDARGUMENTS;
614 pluginImportUri = positionalArgs[1];
615 pluginImportVersion = positionalArgs[2];
616 if (positionalArgs.size() >= 4)
617 pluginImportPath = positionalArgs[3];
618 } else if (action == Path) {
619 if (positionalArgs.size() != 2 && positionalArgs.size() != 3) {
620 qWarning() << "Incorrect number of positional arguments";
621 return EXIT_INVALIDARGUMENTS;
623 pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]);
624 if (positionalArgs.size() == 3)
625 pluginImportVersion = positionalArgs[2];
626 } else if (action == Builtins) {
627 if (positionalArgs.size() != 1) {
628 qWarning() << "Incorrect number of positional arguments";
629 return EXIT_INVALIDARGUMENTS;
635 if (!pluginImportPath.isEmpty()) {
636 QDir cur = QDir::current();
637 cur.cd(pluginImportPath);
638 pluginImportPath = cur.absolutePath();
639 QDir::setCurrent(pluginImportPath);
640 engine.addImportPath(pluginImportPath);
643 // load the QtQuick 2 plugin
645 QByteArray code("import QtQuick 2.0\nQtObject {}");
646 QQmlComponent c(&engine);
647 c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loadqtquick2.qml"));
649 if (!c.errors().isEmpty()) {
650 foreach (const QQmlError &error, c.errors())
651 qWarning() << error.toString();
652 return EXIT_IMPORTERROR;
656 // find all QMetaObjects reachable from the builtin module
657 QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(&engine);
658 QList<QQmlType *> defaultTypes = QQmlMetaType::qmlTypes();
660 // add some otherwise unreachable QMetaObjects
661 defaultReachable.insert(&QQuickMouseEvent::staticMetaObject);
662 // QQuickKeyEvent, QQuickPinchEvent, QQuickDropEvent are not exported
664 // this will hold the meta objects we want to dump information of
665 QSet<const QMetaObject *> metas;
667 if (action == Builtins) {
668 metas = defaultReachable;
670 // find a valid QtQuick import
671 QByteArray importCode;
672 QQmlType *qtObjectType = QQmlMetaType::qmlType(&QObject::staticMetaObject);
674 qWarning() << "Could not find QtObject type";
675 importCode = QByteArray("import QtQuick 2.0\n");
677 QString module = qtObjectType->qmlTypeName();
678 module = module.mid(0, module.lastIndexOf(QLatin1Char('/')));
679 importCode = QString("import %1 %2.%3\n").arg(module,
680 QString::number(qtObjectType->majorVersion()),
681 QString::number(qtObjectType->minorVersion())).toUtf8();
684 // find all QMetaObjects reachable when the specified module is imported
685 if (action != Path) {
686 importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toLatin1();
688 // pluginImportVersion can be empty
689 importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toLatin1();
692 // create a component with these imports to make sure the imports are valid
693 // and to populate the declarative meta type system
695 QByteArray code = importCode;
696 code += "QtObject {}";
697 QQmlComponent c(&engine);
699 c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml"));
701 if (!c.errors().isEmpty()) {
702 foreach (const QQmlError &error, c.errors())
703 qWarning() << error.toString();
704 return EXIT_IMPORTERROR;
708 QSet<const QMetaObject *> candidates = collectReachableMetaObjects(&engine, defaultTypes);
709 candidates.subtract(defaultReachable);
711 // Also eliminate meta objects with the same classname.
712 // This is required because extended objects seem not to share
713 // a single meta object instance.
714 QSet<QByteArray> defaultReachableNames;
715 foreach (const QMetaObject *mo, defaultReachable)
716 defaultReachableNames.insert(QByteArray(mo->className()));
717 foreach (const QMetaObject *mo, candidates) {
718 if (!defaultReachableNames.contains(mo->className()))
723 // setup static rewrites of type names
724 cppToId.insert("QString", "string");
725 cppToId.insert("QQmlEasingValueType::Type", "Type");
727 // start dumping data
729 QmlStreamWriter qml(&bytes);
731 qml.writeStartDocument();
732 qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 1);
733 qml.write(QString("\n"
734 "// This file describes the plugin-supplied types contained in the library.\n"
735 "// It is used for QML tooling purposes only.\n"
737 "// This file was auto-generated with the command '%1'.\n"
738 "\n").arg(args.join(QLatin1String(" "))));
739 qml.writeStartObject("Module");
741 // put the metaobjects into a map so they are always dumped in the same order
742 QMap<QString, const QMetaObject *> nameToMeta;
743 foreach (const QMetaObject *meta, metas)
744 nameToMeta.insert(convertToId(meta), meta);
748 dumper.setRelocatableModuleUri(pluginImportUri);
749 foreach (const QMetaObject *meta, nameToMeta) {
753 // define QEasingCurve as an extension of QQmlEasingValueType, this way
754 // properties using the QEasingCurve type get useful type information.
755 if (pluginImportUri.isEmpty())
756 dumper.writeEasingCurve();
758 qml.writeEndObject();
759 qml.writeEndDocument();
761 std::cout << bytes.constData() << std::flush;
763 // workaround to avoid crashes on exit
765 timer.setSingleShot(true);
766 timer.setInterval(0);
767 QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit()));