aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2016-04-28 12:24:50 +0200
committerMitch Curtis <mitch.curtis@theqtcompany.com>2016-04-28 10:49:49 +0000
commit1913b0a1233597210091e7a73757fab39ff40fc7 (patch)
tree36fb63efecc75162cb0468bd0054d0d824f68c0a
parent56a82a531771f13adbe74ee08d11b058a87beee2 (diff)
Abort application if QJSEngine is constructed before QCoreApplication
QJSEngine requires a QCoreApplication instance in order to function correctly, and 57f7fe3e enforces this further. However, currently an application will simply crash because of accessing a non-existent QCoreApplication instance. This patch makes it clear to the user that they need to construct an instance first. Change-Id: Ieaef005ef03da250cc60457b4b1a4baa5db81215 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/qml/jsapi/qjsengine.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index 4241213c09..5bcc4600a2 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -247,6 +247,11 @@ Q_DECLARE_METATYPE(QList<int>)
QT_BEGIN_NAMESPACE
+static void checkForApplicationInstance()
+{
+ if (!QCoreApplication::instance())
+ qFatal("QJSEngine: Must construct a QCoreApplication before a QJSEngine");
+}
/*!
Constructs a QJSEngine object.
@@ -258,6 +263,8 @@ QJSEngine::QJSEngine()
: QObject(*new QJSEnginePrivate, 0)
, d(new QV8Engine(this))
{
+ checkForApplicationInstance();
+
QJSEnginePrivate::addToDebugServer(this);
}
@@ -272,6 +279,8 @@ QJSEngine::QJSEngine(QObject *parent)
: QObject(*new QJSEnginePrivate, parent)
, d(new QV8Engine(this))
{
+ checkForApplicationInstance();
+
QJSEnginePrivate::addToDebugServer(this);
}
@@ -282,6 +291,7 @@ QJSEngine::QJSEngine(QJSEnginePrivate &dd, QObject *parent)
: QObject(dd, parent)
, d(new QV8Engine(this))
{
+ checkForApplicationInstance();
}
/*!