core: run full destruction sequence before exiting
Fixes QTimer messages.
This commit is contained in:
parent
3033cba52d
commit
6efa05a8eb
|
@ -52,6 +52,9 @@ EngineGeneration::~EngineGeneration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineGeneration::destroy() {
|
void EngineGeneration::destroy() {
|
||||||
|
if (this->destroying) return;
|
||||||
|
this->destroying = true;
|
||||||
|
|
||||||
if (this->watcher != nullptr) {
|
if (this->watcher != nullptr) {
|
||||||
// Multiple generations can detect a reload at the same time.
|
// Multiple generations can detect a reload at the same time.
|
||||||
QObject::disconnect(this->watcher, nullptr, this, nullptr);
|
QObject::disconnect(this->watcher, nullptr, this, nullptr);
|
||||||
|
@ -71,7 +74,12 @@ void EngineGeneration::destroy() {
|
||||||
|
|
||||||
delete this->engine;
|
delete this->engine;
|
||||||
this->engine = nullptr;
|
this->engine = nullptr;
|
||||||
|
|
||||||
|
auto terminate = this->shouldTerminate;
|
||||||
|
auto code = this->exitCode;
|
||||||
delete this;
|
delete this;
|
||||||
|
|
||||||
|
if (terminate) QCoreApplication::exit(code);
|
||||||
});
|
});
|
||||||
|
|
||||||
this->root->deleteLater();
|
this->root->deleteLater();
|
||||||
|
@ -80,11 +88,18 @@ void EngineGeneration::destroy() {
|
||||||
// the engine has never been used, no need to clean up
|
// the engine has never been used, no need to clean up
|
||||||
delete this->engine;
|
delete this->engine;
|
||||||
this->engine = nullptr;
|
this->engine = nullptr;
|
||||||
|
|
||||||
|
auto terminate = this->shouldTerminate;
|
||||||
|
auto code = this->exitCode;
|
||||||
delete this;
|
delete this;
|
||||||
|
|
||||||
|
if (terminate) QCoreApplication::exit(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineGeneration::shutdown() {
|
void EngineGeneration::shutdown() {
|
||||||
|
if (this->destroying) return;
|
||||||
|
|
||||||
delete this->root;
|
delete this->root;
|
||||||
this->root = nullptr;
|
this->root = nullptr;
|
||||||
delete this->engine;
|
delete this->engine;
|
||||||
|
@ -100,9 +115,8 @@ void EngineGeneration::onReload(EngineGeneration* old) {
|
||||||
old->assignIncubationController();
|
old->assignIncubationController();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* app = QCoreApplication::instance();
|
QObject::connect(this->engine, &QQmlEngine::quit, this, &EngineGeneration::quit);
|
||||||
QObject::connect(this->engine, &QQmlEngine::quit, app, &QCoreApplication::quit);
|
QObject::connect(this->engine, &QQmlEngine::exit, this, &EngineGeneration::exit);
|
||||||
QObject::connect(this->engine, &QQmlEngine::exit, app, &QCoreApplication::exit);
|
|
||||||
|
|
||||||
this->root->reload(old == nullptr ? nullptr : old->root);
|
this->root->reload(old == nullptr ? nullptr : old->root);
|
||||||
this->singletonRegistry.onReload(old == nullptr ? nullptr : &old->singletonRegistry);
|
this->singletonRegistry.onReload(old == nullptr ? nullptr : &old->singletonRegistry);
|
||||||
|
@ -266,6 +280,17 @@ void EngineGeneration::incubationControllerDestroyed() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EngineGeneration::quit() {
|
||||||
|
this->shouldTerminate = true;
|
||||||
|
this->destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineGeneration::exit(int code) {
|
||||||
|
this->shouldTerminate = true;
|
||||||
|
this->exitCode = code;
|
||||||
|
this->destroy();
|
||||||
|
}
|
||||||
|
|
||||||
void EngineGeneration::assignIncubationController() {
|
void EngineGeneration::assignIncubationController() {
|
||||||
QQmlIncubationController* controller = nullptr;
|
QQmlIncubationController* controller = nullptr;
|
||||||
if (this->incubationControllers.isEmpty()) controller = &this->delayedIncubationController;
|
if (this->incubationControllers.isEmpty()) controller = &this->delayedIncubationController;
|
||||||
|
|
|
@ -61,9 +61,15 @@ private slots:
|
||||||
void onFileChanged(const QString& name);
|
void onFileChanged(const QString& name);
|
||||||
void onDirectoryChanged();
|
void onDirectoryChanged();
|
||||||
void incubationControllerDestroyed();
|
void incubationControllerDestroyed();
|
||||||
|
void quit();
|
||||||
|
void exit(int code);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void postReload();
|
void postReload();
|
||||||
void assignIncubationController();
|
void assignIncubationController();
|
||||||
QVector<QPair<QQmlIncubationController*, QObject*>> incubationControllers;
|
QVector<QPair<QQmlIncubationController*, QObject*>> incubationControllers;
|
||||||
|
|
||||||
|
bool destroying = false;
|
||||||
|
bool shouldTerminate = false;
|
||||||
|
int exitCode = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue