From 599637502d8f9239bf5b29c766e082bb22a07f0f Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 12 Feb 2024 23:02:06 +0000 Subject: [PATCH] Don't instantiate QApplication/QCoreApplication when running CLI commands QApplication takes around a second to be constructed - annoying when all we want to do is run a CLI command --- src/Application.cpp | 36 ++++++++++++++++++------------------ src/Application.hpp | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 9559b9e5..72014fca 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -26,20 +26,6 @@ using namespace Exceptions; Application::Application(std::vector&& arguments) : arguments(std::move(arguments)) - , qtApplication( - ( - Thread::blockAllSignals(), - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true), -#ifndef BLOOM_DEBUG_BUILD - QCoreApplication::addLibraryPath(QString::fromStdString(Services::PathService::applicationDirPath() + "/plugins")), -#endif -#ifndef EXCLUDE_INSIGHT - QApplication(this->qtApplicationArgc, this->qtApplicationArgv.data()) -#else - QCoreApplication(this->qtApplicationArgc, this->qtApplicationArgv.data()) -#endif - ) - ) {} int Application::run() { @@ -93,11 +79,11 @@ int Application::run() { * * This allows us to use Qt's event loop whilst still being able to process our own events. */ - auto* eventDispatchTimer = new QTimer(&(this->qtApplication)); + auto* eventDispatchTimer = new QTimer(this->qtApplication.get()); QObject::connect(eventDispatchTimer, &QTimer::timeout, this, &Application::dispatchEvents); eventDispatchTimer->start(100); - this->qtApplication.exec(); + this->qtApplication->exec(); } catch (const InvalidConfig& exception) { Logger::error("Invalid project configuration (bloom.yaml) - " + exception.getMessage()); @@ -144,6 +130,20 @@ std::map> Application::getCommandHandlersByCom } void Application::startup() { + Thread::blockAllSignals(); + + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); + +#ifndef BLOOM_DEBUG_BUILD + QCoreApplication::addLibraryPath(QString::fromStdString(Services::PathService::applicationDirPath() + "/plugins")), +#endif + +#ifndef EXCLUDE_INSIGHT + this->qtApplication = std::make_unique(this->qtApplicationArgc, this->qtApplicationArgv.data()); +#else + this->qtApplication = std::make_unique(this->qtApplicationArgc, this->qtApplicationArgv.data()); +#endif + auto& applicationEventListener = this->applicationEventListener; EventManager::registerListener(applicationEventListener); applicationEventListener->registerCallbackForEventType( @@ -219,7 +219,7 @@ void Application::triggerShutdown() { } #endif - this->qtApplication.exit(EXIT_SUCCESS); + this->qtApplication->exit(EXIT_SUCCESS); } void Application::loadProjectSettings() { @@ -601,7 +601,7 @@ void Application::activateInsight() { this->environmentConfig.value(), this->insightConfig.value(), this->projectSettings.value().insightSettings, - &(this->qtApplication) + this->qtApplication.get() ); } diff --git a/src/Application.hpp b/src/Application.hpp index dd41698c..8d9d4031 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -61,9 +61,9 @@ private: std::array qtApplicationArgv = {this->qtApplicationName.data()}; int qtApplicationArgc = 1; #ifndef EXCLUDE_INSIGHT - QApplication qtApplication; + std::unique_ptr qtApplication = nullptr; #else - QCoreApplication qtApplication; + std::unique_ptr qtApplication = nullptr; #endif EventListenerPointer applicationEventListener = std::make_shared("ApplicationEventListener");