From 97cbef99cbd35b22a17bf29ed406b20d4d35680c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 5 Dec 2011 14:10:59 +0000 Subject: [PATCH] Fix crash when QtQuick 2.0 wasn't imported The QML compiler still tried to resolve the implicit "Component" element within the QtQuick 2.0 namespace. Task-number: QTBUG-23017 Change-Id: I62ae962f58787910a76f76c872daa08874b5df56 Reviewed-by: Roberto Raggi --- src/declarative/qml/qdeclarativecompiler.cpp | 28 ++++++++++++++++--------- src/declarative/qml/qdeclarativecompiler_p.h | 1 + src/declarative/qml/qdeclarativecomponent_p.h | 2 +- src/declarative/qml/qdeclarativeengine.cpp | 2 + 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index aa27d79..5500efa 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -90,12 +90,14 @@ static QString id_string(QLatin1String("id")); static QString on_string(QLatin1String("on")); static QString Changed_string(QLatin1String("Changed")); static QString Component_string(QLatin1String("Component")); +static QString Component_import_string(QLatin1String("QML/Component")); /*! Instantiate a new QDeclarativeCompiler. */ QDeclarativeCompiler::QDeclarativeCompiler(QDeclarativePool *pool) -: pool(pool), output(0), engine(0), unitRoot(0), unit(0), componentStats(0) +: pool(pool), output(0), engine(0), unitRoot(0), unit(0), cachedComponentTypeRef(-1), + componentStats(0) { if (compilerStatDump()) componentStats = pool->New(); @@ -829,6 +831,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, this->engine = 0; this->enginePrivate = 0; this->unit = 0; + this->cachedComponentTypeRef = -1; this->unitRoot = 0; return !isError(); @@ -1586,16 +1589,21 @@ bool QDeclarativeCompiler::buildSubObject(QDeclarativeScript::Object *obj, const int QDeclarativeCompiler::componentTypeRef() { - QDeclarativeType *t = QDeclarativeMetaType::qmlType(QLatin1String("QtQuick/Component"),2,0); - for (int ii = output->types.count() - 1; ii >= 0; --ii) { - if (output->types.at(ii).type == t) - return ii; + if (cachedComponentTypeRef == -1) { + QDeclarativeType *t = QDeclarativeMetaType::qmlType(Component_import_string,1,0); + for (int ii = output->types.count() - 1; ii >= 0; --ii) { + if (output->types.at(ii).type == t) { + cachedComponentTypeRef = ii; + return ii; + } + } + QDeclarativeCompiledData::TypeReference ref; + ref.className = Component_string; + ref.type = t; + output->types << ref; + cachedComponentTypeRef = output->types.count() - 1; } - QDeclarativeCompiledData::TypeReference ref; - ref.className = Component_string; - ref.type = t; - output->types << ref; - return output->types.count() - 1; + return cachedComponentTypeRef; } bool QDeclarativeCompiler::buildSignal(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj, diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 9a67f32..77f5b86 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -414,6 +414,7 @@ private: QDeclarativeEnginePrivate *enginePrivate; QDeclarativeScript::Object *unitRoot; QDeclarativeTypeData *unit; + int cachedComponentTypeRef; // Compiler component statistics. Only collected if QML_COMPILER_STATS=1 struct ComponentStat diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h index 49b3d03..1e6cbc8 100644 --- a/src/declarative/qml/qdeclarativecomponent_p.h +++ b/src/declarative/qml/qdeclarativecomponent_p.h @@ -124,7 +124,7 @@ public: } }; -class QDeclarativeComponentAttached : public QObject +class Q_AUTOTEST_EXPORT QDeclarativeComponentAttached : public QObject { Q_OBJECT public: diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index ee42f0b..7d5bb59 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -424,6 +424,8 @@ void QDeclarativeEnginePrivate::init() // is blocking on the thread that initialize the network access manager. QNetworkConfigurationManager man; + qmlRegisterType("QML", 1, 0, "Component"); + firstTime = false; } -- 1.7.2.5