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>
This commit is contained in:
Mitch Curtis 2016-04-28 12:24:50 +02:00
parent 56a82a5317
commit 1913b0a123
1 changed files with 10 additions and 0 deletions

View File

@ -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();
}
/*!