Define global var that is type of QScriptEngine throws exception
-
in common.h i declare global var as
@
extern QScriptEngine engine;
@
in main.cpp, i define it as@
#include "common.h"QScriptEngine engine;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);MainWindow w; w.show(); return a.exec();
}
@
when i start application, it throws Excetpion:this application has requested the Runtime to terminate it in an unusual way.
please contact the application's support team for more information.return code 3
Any idea what I can do?
Thanks a lot.
Edit: Fixed code tags. Please wrap with @; mlong
-
You cannot create a script engine (and many other Qt objects) as long as you haven't created a Q(Core)Application.
@
QScriptEngine* engine;int main(int argc, char *argv[])
{
QApplication a(argc, argv);engine = new QScriptEngine(&a); MainWindow w; w.show(); return a.exec();
}
@
Passing the script engine as a global variable is a very questionable design decision. A better choice would be subclassing QApplication and adding it as a member or storing it as a property of QApplication (the QApplication instance is accessible from anywhere using qApp() or QCoreApplication::instance()).