From 1913b0a1233597210091e7a73757fab39ff40fc7 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 28 Apr 2016 12:24:50 +0200 Subject: 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 --- src/qml/jsapi/qjsengine.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/qml/jsapi/qjsengine.cpp') 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) 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(); } /*! -- cgit v1.2.3