From bdbc3ff0a32bb37a32dc4825413e60f9d75e5007 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 14 Jul 2011 09:03:07 +0200 Subject: qmldump: Fix creation of objects from QDeclarativeTypes. Previously, the import statement was not necessarily set up correctly for the type we wanted to instantiate. We simply use QDeclarativeType::create now and thus can skip finding the right import. Mirrors qtcreator/f326bd067d455e979b5d83195e19581a9e2fd494 Reviewed-by: Roberto Raggi --- tools/qmlplugindump/main.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index ae06d02..6bef8d4 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -147,7 +147,7 @@ QByteArray convertToId(const QByteArray &cppName) return cppToId.value(cppName, cppName); } -QSet collectReachableMetaObjects(const QString &importCode, QDeclarativeEngine *engine) +QSet collectReachableMetaObjects(const QList &skip = QList()) { QSet metas; metas.insert(FriendlyQObject::qtMeta()); @@ -195,7 +195,9 @@ QSet collectReachableMetaObjects(const QString &importCode, // find even more QMetaObjects by instantiating QML types and running // over the instances - foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + foreach (QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + if (skip.contains(ty)) + continue; if (ty->isExtendedType()) continue; if (!ty->isCreatable()) @@ -208,21 +210,14 @@ QSet collectReachableMetaObjects(const QString &importCode, if (tyName.isEmpty()) continue; - QByteArray code = importCode.toUtf8(); - code += tyName; - code += " {}\n"; - - QDeclarativeComponent c(engine); - c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typeinstance.qml")); - inObjectInstantiation = tyName; - QObject *object = c.create(); + QObject *object = ty->create(); inObjectInstantiation.clear(); if (object) collectReachableMetaObjects(object, &metas); else - qWarning() << "Could not create" << tyName << ":" << c.errorString(); + qWarning() << "Could not create" << tyName; } return metas; @@ -548,8 +543,8 @@ int main(int argc, char *argv[]) } // find all QMetaObjects reachable from the builtin module - QByteArray importCode("import QtQuick 1.0\n"); - QSet defaultReachable = collectReachableMetaObjects(importCode, engine); + QSet defaultReachable = collectReachableMetaObjects(); + QList defaultTypes = QDeclarativeMetaType::qmlTypes(); // this will hold the meta objects we want to dump information of QSet metas; @@ -557,6 +552,20 @@ int main(int argc, char *argv[]) if (action == Builtins) { metas = defaultReachable; } else { + // find a valid QtQuick import + QByteArray importCode; + QDeclarativeType *qtObjectType = QDeclarativeMetaType::qmlType(&QObject::staticMetaObject); + if (!qtObjectType) { + qWarning() << "Could not find QtObject type"; + importCode = QByteArray("import QtQuick 1.0\n"); + } else { + QByteArray module = qtObjectType->qmlTypeName(); + module = module.mid(0, module.lastIndexOf('/')); + importCode = QString("import %1 %2.%3\n").arg(module, + QString::number(qtObjectType->majorVersion()), + QString::number(qtObjectType->minorVersion())).toUtf8(); + } + // find all QMetaObjects reachable when the specified module is imported if (action != Path) { importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); @@ -581,7 +590,7 @@ int main(int argc, char *argv[]) } } - QSet candidates = collectReachableMetaObjects(importCode, engine); + QSet candidates = collectReachableMetaObjects(defaultTypes); candidates.subtract(defaultReachable); // Also eliminate meta objects with the same classname. -- cgit v0.12