Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Define global var that is type of QScriptEngine throws exception
Qt 6.11 is out! See what's new in the release blog

Define global var that is type of QScriptEngine throws exception

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qstudy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved