mirror of https://github.com/CGAL/cgal
Allocate the QJSEngine on the heap
This commit is contained in:
parent
67441a3772
commit
134b464aaa
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent)
|
MainWindow::MainWindow(QWidget* parent)
|
||||||
: CGAL::Qt::DemosMainWindow(parent)
|
: CGAL::Qt::DemosMainWindow(parent), myEngine(new QJSEngine())
|
||||||
{
|
{
|
||||||
ui = new Ui::MainWindow;
|
ui = new Ui::MainWindow;
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
@ -40,14 +40,14 @@ MainWindow::MainWindow(QWidget* parent)
|
||||||
connect(this, SIGNAL(openRecentFile(QString)),
|
connect(this, SIGNAL(openRecentFile(QString)),
|
||||||
this, SLOT(open(QString)));
|
this, SLOT(open(QString)));
|
||||||
|
|
||||||
QJSValue mainWindow = myEngine.newQObject(this);
|
QJSValue mainWindow = myEngine->newQObject(this);
|
||||||
myEngine.globalObject().setProperty("main_window", mainWindow);
|
myEngine->globalObject().setProperty("main_window", mainWindow);
|
||||||
readSettings();
|
readSettings();
|
||||||
std::ifstream script("init.js");
|
std::ifstream script("init.js");
|
||||||
if(script.good()){
|
if(script.good()){
|
||||||
std::string line;
|
std::string line;
|
||||||
while(getline(script, line)){
|
while(getline(script, line)){
|
||||||
myEngine.evaluate(line.c_str());
|
myEngine->evaluate(line.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +57,8 @@ MainWindow::~MainWindow()
|
||||||
m_pViewer->makeCurrent();
|
m_pViewer->makeCurrent();
|
||||||
// AF I thought this helps to avoid the exception when the program
|
// AF I thought this helps to avoid the exception when the program
|
||||||
// terminates, but it does not
|
// terminates, but it does not
|
||||||
myEngine.globalObject().setProperty("main_window", QJSValue());
|
myEngine->globalObject().setProperty("main_window", QJSValue());
|
||||||
myEngine.collectGarbage();
|
myEngine->collectGarbage();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,19 @@ struct Foo : public QObject
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QJSEngine myEngine;
|
QJSEngine* myEngine;
|
||||||
|
|
||||||
Foo()
|
Foo()
|
||||||
|
: myEngine(new QJSEngine())
|
||||||
{
|
{
|
||||||
QJSValue baz = myEngine.newQObject(this);
|
QJSValue baz = myEngine->newQObject(this);
|
||||||
myEngine.globalObject().setProperty("baz", baz);
|
myEngine->.globalObject().setProperty("baz", baz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar()
|
void bar()
|
||||||
{
|
{
|
||||||
std::cout << "bar()" << std::endl;
|
std::cout << "bar()" << std::endl;
|
||||||
myEngine.evaluate("baz.hello()");
|
myEngine->evaluate("baz.hello()");
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
@ -112,7 +113,7 @@ public:
|
||||||
void on_actionView_cutting_plane_triggered();
|
void on_actionView_cutting_plane_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJSEngine myEngine;
|
QJSEngine* myEngine;
|
||||||
Scene* m_pScene;
|
Scene* m_pScene;
|
||||||
Viewer* m_pViewer;
|
Viewer* m_pViewer;
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue