summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlexpression.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-28 03:59:33 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-28 03:59:33 (GMT)
commiteaab2a271f0d73d5a413902169efe32741208c42 (patch)
treeda00990537be1d2546bbb84d3aac986eccf3dd30 /src/declarative/qml/qmlexpression.cpp
parent5f9091771eaa26db5ad35e4788c13ac011512b61 (diff)
downloadQt-eaab2a271f0d73d5a413902169efe32741208c42.zip
Qt-eaab2a271f0d73d5a413902169efe32741208c42.tar.gz
Qt-eaab2a271f0d73d5a413902169efe32741208c42.tar.bz2
Add a QmlExpression::error() method
QmlExpression should not print errors itself. This is the responsibility of the caller.
Diffstat (limited to 'src/declarative/qml/qmlexpression.cpp')
-rw-r--r--src/declarative/qml/qmlexpression.cpp55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp
index c62756b..8231bf8 100644
--- a/src/declarative/qml/qmlexpression.cpp
+++ b/src/declarative/qml/qmlexpression.cpp
@@ -260,7 +260,8 @@ QVariant QmlExpressionPrivate::evalSSE()
return rv;
}
-void QmlExpressionPrivate::printException(QScriptEngine *scriptEngine)
+void QmlExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine,
+ QmlError &error)
{
if (scriptEngine->hasUncaughtException() &&
scriptEngine->uncaughtException().isError()) {
@@ -277,8 +278,12 @@ void QmlExpressionPrivate::printException(QScriptEngine *scriptEngine)
fileName = QLatin1String("<Unknown File>");
}
- qWarning().nospace() << qPrintable(fileName) << ":" << lineNumber << ": "
- << qPrintable(exception.toString());
+ error.setUrl(QUrl(fileName));
+ error.setLine(lineNumber);
+ error.setColumn(-1);
+ error.setDescription(exception.toString());
+ } else {
+ error = QmlError();
}
}
@@ -321,10 +326,13 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd
if (isUndefined)
*isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException();
+ // Handle exception
if (scriptEngine->hasUncaughtException()) {
- printException(scriptEngine);
+ exceptionToError(scriptEngine, data->error);
scriptEngine->clearExceptions();
return QVariant();
+ } else {
+ data->error = QmlError();
}
if (secondaryScope) {
@@ -418,6 +426,8 @@ QVariant QmlExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined)
\a isUndefined is set to true if the expression resulted in an
undefined value.
+
+ \sa hasError(), error()
*/
QVariant QmlExpression::value(bool *isUndefined)
{
@@ -509,6 +519,43 @@ QObject *QmlExpression::scopeObject() const
return d->data->me;
}
+/*!
+ Returns true if the last call to value() resulted in an error,
+ otherwise false.
+
+ \sa error(), clearError()
+*/
+bool QmlExpression::hasError() const
+{
+ Q_D(const QmlExpression);
+ return d->data->error.isValid();
+}
+
+/*!
+ Clear any expression errors. Calls to hasError() following this will
+ return false.
+
+ \sa hasError(), error()
+*/
+void QmlExpression::clearError()
+{
+ Q_D(QmlExpression);
+ d->data->error = QmlError();
+}
+
+/*!
+ Return any error from the last call to value(). If there was no error,
+ this returns an invalid QmlError instance.
+
+ \sa hasError(), clearError()
+*/
+
+QmlError QmlExpression::error() const
+{
+ Q_D(const QmlExpression);
+ return d->data->error;
+}
+
/*! \internal */
void QmlExpression::__q_notify()
{