August 23, 2011

qstudy qstudy
Lab Rat
1 posts

Define global var that is type of QScriptEngine throws exception


in common.h i declare global var as

  1. extern QScriptEngine engine;

in main.cpp, i define it as

  1. #include "common.h"
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication a(argc, argv);
  8.     MainWindow w;
  11.     return a.exec();
  12. }

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

1 reply

August 23, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2068 posts

You cannot create a script engine (and many other Qt objects) as long as you haven’t created a Q(Core)Application.

  1. QScriptEngine* engine;
  3. int main(int argc, char *argv[])
  4. {
  5.     QApplication a(argc, argv);
  7.     engine = new QScriptEngine(&a);
  9.     MainWindow w;
  12.     return a.exec();
  13. }

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()).

  ‹‹ Nice2See: QTablewidget fit in Widget      [SOLVED] strange output for html bold ››

You must log in to post a reply. Not a member yet? Register here!