diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-12-05 14:10:59 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-05 15:33:39 +0100 |
commit | 97cbef99cbd35b22a17bf29ed406b20d4d35680c (patch) | |
tree | 681c29a045fa08da107015a994c6a0f40b6c95ca /src | |
parent | 5ac2990688c7da6ce872bccc5c08129267887d68 (diff) |
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 <roberto.raggi@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 28 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecomponent_p.h | 2 | ||||
-rw-r--r-- | 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 aa27d7994f..5500efa42f 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<ComponentStats>(); @@ -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 9a67f3213b..77f5b860dc 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 49b3d037ad..1e6cbc8262 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 ee42f0b7c3..7d5bb597ed 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<QDeclarativeComponent>("QML", 1, 0, "Component"); + firstTime = false; } |