}
/*! \internal */
-QQmlExpression::QQmlExpression(QQmlContextData *ctxt,
+QQmlExpression::QQmlExpression(QQmlContextData *ctxt,
QObject *object, const QString &expr, bool isRewritten,
const QString &url, int lineNumber, int columnNumber,
QQmlExpressionPrivate &dd)
/*!
Create a QQmlExpression object that is a child of \a parent.
- The \script provides the expression to be evaluated, the context to evaluate it in,
+ The \a script provides the expression to be evaluated, the context to evaluate it in,
and the scope object to evaluate it with.
This constructor is functionally equivalent to the following, but in most cases
: QObject(*new QQmlExpressionPrivate, parent)
{
Q_D(QQmlExpression);
- bool defaultConstruction = false;
+
+ if (!script.context()->isValid())
+ return;
+
+ bool defaultConstruction = true;
int id = script.d.data()->bindingId;
- if (id < 0) {
- defaultConstruction = true;
- } else {
+ if (id >= 0) {
QQmlContextData *ctxtdata = QQmlContextData::get(script.context());
-
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(script.context()->engine());
- QQmlCompiledData *cdata = 0;
- QQmlTypeData *typeData = 0;
if (engine && ctxtdata && !ctxtdata->url.isEmpty()) {
- typeData = engine->typeLoader.get(ctxtdata->url);
- cdata = typeData->compiledData();
- }
+ QQmlTypeData *typeData = engine->typeLoader.getType(ctxtdata->url);
+ Q_ASSERT(typeData);
- if (cdata)
- d->init(ctxtdata, cdata->primitives.at(id), true, script.scopeObject(),
- cdata->name, script.d.data()->lineNumber, script.d.data()->columnNumber);
- else
- defaultConstruction = true;
+ if (QQmlCompiledData *cdata = typeData->compiledData()) {
+ defaultConstruction = false;
+ d->init(ctxtdata, cdata->primitives.at(id), true, script.scopeObject(),
+ cdata->name, script.d.data()->lineNumber, script.d.data()->columnNumber);
+ }
- if (cdata)
- cdata->release();
- if (typeData)
typeData->release();
+ }
}
if (defaultConstruction)
d->init(QQmlContextData::get(ctxt), expression, scope);
}
-/*!
+/*!
\internal
*/
QQmlExpression::QQmlExpression(QQmlContextData *ctxt, QObject *scope,
}
/*!
- Returns the source file line number for this expression. The source location
+ Returns the source file line number for this expression. The source location
must have been previously set by calling setSourceLocation().
*/
int QQmlExpression::lineNumber() const
/*!
Returns true if the last call to evaluate() resulted in an error,
otherwise false.
-
+
\sa error(), clearError()
*/
bool QQmlExpression::hasError() const
QQmlError QQmlExpression::error() const
{
Q_D(const QQmlExpression);
- return d->error();
+ return d->error(engine());
}
/*!
QString QQmlExpressionPrivate::expressionIdentifier(QQmlJavaScriptExpression *e)
{
QQmlExpressionPrivate *This = static_cast<QQmlExpressionPrivate *>(e);
- return QLatin1String("\"") + This->expression + QLatin1String("\"");
+ return QLatin1Char('"') + This->expression + QLatin1Char('"');
}
QT_END_NAMESPACE