From bd7b72e861bafb71d0ec15d4efa15abb2f696c25 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 28 Mar 2024 06:35:28 +0800 Subject: [PATCH] ui/initApp(): remove temporary QApplication object (#32011) remove temporary QApplication object --- selfdrive/ui/qt/util.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index 9138f8bca5..0bf5f2865e 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -105,20 +105,21 @@ void initApp(int argc, char *argv[], bool disable_hidpi) { std::signal(SIGINT, sigTermHandler); std::signal(SIGTERM, sigTermHandler); - if (disable_hidpi) { + QString app_dir; #ifdef __APPLE__ - // Get the devicePixelRatio, and scale accordingly to maintain 1:1 rendering - QApplication tmp(argc, argv); - qputenv("QT_SCALE_FACTOR", QString::number(1.0 / tmp.devicePixelRatio() ).toLocal8Bit()); -#endif + // Get the devicePixelRatio, and scale accordingly to maintain 1:1 rendering + QApplication tmp(argc, argv); + app_dir = QCoreApplication::applicationDirPath(); + if (disable_hidpi) { + qputenv("QT_SCALE_FACTOR", QString::number(1.0 / tmp.devicePixelRatio()).toLocal8Bit()); } +#else + app_dir = QFileInfo(util::readlink("/proc/self/exe").c_str()).path(); +#endif qputenv("QT_DBL_CLICK_DIST", QByteArray::number(150)); - // ensure the current dir matches the exectuable's directory - QApplication tmp(argc, argv); - QString appDir = QCoreApplication::applicationDirPath(); - QDir::setCurrent(appDir); + QDir::setCurrent(app_dir); setQtSurfaceFormat(); }