diff options
author | Eike Ziller <eike.ziller@qt.io> | 2023-12-06 16:50:15 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2023-12-06 16:50:15 +0100 |
commit | 2e280e1c50d6fb1ac76d84703a060955f0b0a9fa (patch) | |
tree | 12b0260951cf3bf83ebbfcca1a21d4b22793f3ab /src/app | |
parent | 6a97b66592ff0bf76d236f6120cd94e2604283a4 (diff) | |
parent | d1ac2fe45a9a7986bfb9217f14bfc1ca22a9cdd9 (diff) |
Merge remote-tracking branch 'origin/12.0'
Conflicts:
src/plugins/clangcodemodel/clangdfollowsymbol.cpp
src/plugins/debugger/debuggerruncontrol.cpp
src/plugins/projectexplorer/miniprojecttargetselector.cpp
Change-Id: I45b7fee1a1d784c44f2139fb1ede69190d23d6fd
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/main.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp index ef5f5a1eb4..db5b46c437 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -478,6 +478,53 @@ bool startCrashpad(const QString &libexecPath, bool crashReportingEnabled) } #endif +class ShowInGuiHandler +{ +public: + ShowInGuiHandler() + { + instance = this; + oldHandler = qInstallMessageHandler(log); + } + ~ShowInGuiHandler() { qInstallMessageHandler(oldHandler); }; + +private: + static void log(QtMsgType type, const QMessageLogContext &context, const QString &msg) + { + instance->messages += msg; + if (type == QtFatalMsg) { + // Show some kind of GUI with collected messages before exiting. + // For Windows, Qt already uses a dialog. + if (Utils::HostOsInfo::isLinuxHost()) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && QT_VERSION < QT_VERSION_CHECK(6, 5, 3)) \ + || (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 6, 1)) + // Information about potentially missing libxcb-cursor0 is printed by Qt since Qt 6.5.3 and Qt 6.6.1 + // Add it manually for other versions >= 6.5.0 + instance->messages.prepend("From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to " + "load the Qt xcb platform plugin."); +#endif + if (QFile::exists("/usr/bin/xmessage")) + QProcess::startDetached("/usr/bin/xmessage", {instance->messages.join("\n")}); + } else if (Utils::HostOsInfo::isMacHost()) { + QProcess::startDetached("/usr/bin/osascript", + {"-e", + "display dialog \"" + + instance->messages.join("\n").replace("\"", "\\\"") + + "\" buttons \"OK\" with title \"" + + Core::Constants::IDE_DISPLAY_NAME + + " Failed to Start\""}); + } + } + instance->oldHandler(type, context, msg); + }; + + static ShowInGuiHandler *instance; + QStringList messages; + QtMessageHandler oldHandler = nullptr; +}; + +ShowInGuiHandler *ShowInGuiHandler::instance = nullptr; + int main(int argc, char **argv) { Restarter restarter(argc, argv); @@ -600,9 +647,13 @@ int main(int argc, char **argv) int numberOfArguments = static_cast<int>(options.appArguments.size()); + // create a custom Qt message handler that shows messages in a bare bones UI + // if creation of the QGuiApplication fails. + auto handler = std::make_unique<ShowInGuiHandler>(); std::unique_ptr<SharedTools::QtSingleApplication> appPtr(SharedTools::createApplication(QLatin1String(Core::Constants::IDE_DISPLAY_NAME), numberOfArguments, options.appArguments.data())); + handler.reset(); SharedTools::QtSingleApplication &app = *appPtr; QCoreApplication::setApplicationName(Core::Constants::IDE_CASED_ID); QCoreApplication::setApplicationVersion(QLatin1String(Core::Constants::IDE_VERSION_LONG)); |