Fix script engine deletion
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -170,7 +170,7 @@ void ScriptEngine::runInThread() { · 169 unmodified lines | |||
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | _isThreaded = true; | 172 | _isThreaded = true; |
| 173 | QThread* workerThread = new QThread(); // thread is not owned, so we need to manage the delete | 173 | QThread* workerThread = new QThread(this); // thread is not owned, so we need to manage the delete |
| 174 | QString scriptEngineName = QString("Script Thread:") + getFilename(); | 174 | QString scriptEngineName = QString("Script Thread:") + getFilename(); |
| 175 | workerThread->setObjectName(scriptEngineName); | 175 | workerThread->setObjectName(scriptEngineName); |
| 176 | 176 | ||
| @@ -184,9 +184,6 @@ void ScriptEngine::runInThread() { · 7 unmodified lines | |||
| 184 | // tell the thread to stop when the script engine is done | 184 | // tell the thread to stop when the script engine is done |
| 185 | connect(this, &ScriptEngine::doneRunning, workerThread, &QThread::quit); | 185 | connect(this, &ScriptEngine::doneRunning, workerThread, &QThread::quit); |
| 186 | 186 | ||
| 187 | // when the thread is finished, add thread to the deleteLater queue | ||
| 188 | connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater); | ||
| 189 | |||
| 190 | moveToThread(workerThread); | 187 | moveToThread(workerThread); |
| 191 | 188 | ||
| 192 | // Starts an event loop, and emits workerThread->started() | 189 | // Starts an event loop, and emits workerThread->started() |
| @@ -199,7 +196,7 @@ void ScriptEngine::waitTillDoneRunning() { · 6 unmodified lines | |||
| 199 | 196 | ||
| 200 | // NOTE: waitTillDoneRunning() will be called on the main Application thread, inside of stopAllScripts() | 197 | // NOTE: waitTillDoneRunning() will be called on the main Application thread, inside of stopAllScripts() |
| 201 | // we want the application thread to continue to process events, because the scripts will likely need to | 198 | // we want the application thread to continue to process events, because the scripts will likely need to |
| 202 | // marshall messages across to the main thread. For example if they access Settings or Meny in any of their | 199 | // marshall messages across to the main thread. For example if they access Settings or Menu in any of their |
| 203 | // shutdown code. | 200 | // shutdown code. |
| 204 | while (thread()->isRunning()) { | 201 | while (thread()->isRunning()) { |
| 205 | // process events for the main application thread, allowing invokeMethod calls to pass between threads | 202 | // process events for the main application thread, allowing invokeMethod calls to pass between threads |