summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativecontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/qdeclarativecontext.cpp')
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 9307bcc..ba4da95 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -202,6 +202,12 @@ QDeclarativeContext::~QDeclarativeContext()
d->data->destroy();
}
+bool QDeclarativeContext::isValid() const
+{
+ Q_D(const QDeclarativeContext);
+ return d->data && d->data->isValid();
+}
+
/*!
Return the context's QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the
QDeclarativeEngine was destroyed.
@@ -245,6 +251,11 @@ void QDeclarativeContext::setContextObject(QObject *object)
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set context object on invalid context.");
+ return;
+ }
+
data->contextObject = object;
}
@@ -264,6 +275,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, const QVariant
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set property on invalid context.");
+ return;
+ }
+
if (data->engine) {
bool ok;
QObject *o = QDeclarativeEnginePrivate::get(data->engine)->toQObject(value, &ok);
@@ -305,6 +321,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, QObject *value
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set property on invalid context.");
+ return;
+ }
+
if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine);
int idx = data->propertyNames->value(name);