From 4c2d7a7e41fabefa1c4519ad6adebcad09808fbe Mon Sep 17 00:00:00 2001 From: outfoxxed <outfoxxed@outfoxxed.me> Date: Thu, 17 Oct 2024 13:15:09 -0700 Subject: [PATCH] crash: print warning messages for run/buildtime Qt version mismatch --- README.md | 5 +++++ src/core/main.cpp | 23 +++++++++++++++++++++++ src/crash/interface.cpp | 33 ++++++++++++++++++++++++++++----- src/crash/main.cpp | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 726bf22a..82f912fd 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,11 @@ It is not managed by us and should be looked over before use. [AUR package]: https://aur.archlinux.org/packages/quickshell +> [!CAUTION] +> The AUR provides no way to force the quickshell package to rebuild when the Qt version changes. +> If you experience crashes after updating Qt, please try rebuilding Quickshell against the +> current Qt version before opening an issue. + ## Fedora (COPR) Quickshell has a third party [Fedora COPR package] available under the same name. It is not managed by us and should be looked over before use. diff --git a/src/core/main.cpp b/src/core/main.cpp index 287af3b1..cc57cc61 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -4,6 +4,7 @@ #include <cerrno> #include <cstdio> #include <cstdlib> +#include <cstring> #include <limits> #include <string> #include <vector> @@ -176,6 +177,7 @@ struct CommandState { } subcommand; struct { + bool checkCompat = false; bool printVersion = false; bool killAll = false; bool noDuplicate = false; @@ -290,6 +292,8 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { addDebugOptions(&cli); { + cli.add_option_group("")->add_flag("--private-check-compat", state.misc.checkCompat); + cli.add_flag("-V,--version", state.misc.printVersion) ->description("Print quickshell's version and exit."); @@ -378,6 +382,18 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { CLI11_PARSE(cli, argc, argv); + if (state.misc.checkCompat) { + if (strcmp(qVersion(), QT_VERSION_STR) != 0) { + QTextStream(stdout) << "\033[31mCOMPATIBILITY WARNING: Quickshell was built against Qt " + << QT_VERSION_STR << " but the system has updated to Qt " << qVersion() + << " without rebuilding the package. This is likely to cause crashes, so " + "you must rebuild the quickshell package.\n"; + return 1; + } + + return 0; + } + // Has to happen before extra threads are spawned. if (state.misc.daemonize) { auto closepipes = std::array<int, 2>(); @@ -451,6 +467,13 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { } else if (*state.subcommand.msg) { return msgInstance(state); } else { + if (strcmp(qVersion(), QT_VERSION_STR) != 0) { + qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR + << "but the system has updated to Qt" << qVersion() + << "without rebuilding the package. This is likely to cause crashes, so " + "the quickshell package must be rebuilt.\n"; + } + return launchFromCommand(state, coreApplication); } diff --git a/src/crash/interface.cpp b/src/crash/interface.cpp index 7691b260..c6334401 100644 --- a/src/crash/interface.cpp +++ b/src/crash/interface.cpp @@ -1,8 +1,10 @@ #include "interface.hpp" +#include <cstring> #include <utility> #include <qapplication.h> #include <qboxlayout.h> +#include <qconfig.h> #include <qdesktopservices.h> #include <qfont.h> #include <qfontinfo.h> @@ -10,6 +12,7 @@ #include <qnamespace.h> #include <qobject.h> #include <qpushbutton.h> +#include <qtversion.h> #include <qwidget.h> #include "build.hpp" @@ -37,20 +40,40 @@ CrashReporterGui::CrashReporterGui(QString reportFolder, int pid) auto* mainLayout = new QVBoxLayout(this); - mainLayout->addWidget(new QLabel( - "<u>Quickshell has crashed. Please submit a bug report to help us fix it.</u>", - this - )); + auto qtVersionMatches = strcmp(qVersion(), QT_VERSION_STR) == 0; + if (qtVersionMatches) { + mainLayout->addWidget(new QLabel( + "<u>Quickshell has crashed. Please submit a bug report to help us fix it.</u>", + this + )); + } else { + mainLayout->addWidget( + new QLabel("<u>Quickshell has crashed, likely due to a Qt version mismatch.</u>", this) + ); + } mainLayout->addSpacing(textHeight); mainLayout->addWidget(new QLabel("General information", this)); mainLayout->addWidget(new ReportLabel("Git Revision:", GIT_REVISION, this)); + mainLayout->addWidget(new QLabel( + QString::fromLatin1("Runtime Qt version: ") % qVersion() % ", Buildtime Qt version: " + % QT_VERSION_STR, + this + )); mainLayout->addWidget(new ReportLabel("Crashed process ID:", QString::number(pid), this)); mainLayout->addWidget(new ReportLabel("Crash report folder:", this->reportFolder, this)); mainLayout->addSpacing(textHeight); - mainLayout->addWidget(new QLabel("Please open a bug report for this issue via github or email.")); + if (qtVersionMatches) { + mainLayout->addWidget(new QLabel("Please open a bug report for this issue via github or email.") + ); + } else { + mainLayout->addWidget(new QLabel( + "Please rebuild Quickshell against the current Qt version.\n" + "If this does not solve the problem, please open a bug report via github or email." + )); + } mainLayout->addWidget(new ReportLabel( "Github:", diff --git a/src/crash/main.cpp b/src/crash/main.cpp index 08c38892..1beb6749 100644 --- a/src/crash/main.cpp +++ b/src/crash/main.cpp @@ -4,6 +4,7 @@ #include <qapplication.h> #include <qconfig.h> +#include <qcoreapplication.h> #include <qdatastream.h> #include <qdir.h> #include <qfile.h> @@ -12,7 +13,6 @@ #include <qtenvironmentvariables.h> #include <qtextstream.h> #include <qtversion.h> -#include <qversiontagging.h> #include <sys/sendfile.h> #include <sys/types.h>