diff --git a/src/core/platformmenu.cpp b/src/core/platformmenu.cpp index 0f416a20..37eb4654 100644 --- a/src/core/platformmenu.cpp +++ b/src/core/platformmenu.cpp @@ -4,7 +4,9 @@ #include #include +#include #include +#include #include #include #include @@ -74,7 +76,13 @@ void PlatformMenuEntry::registerCreationHook(std::functionqmenu == nullptr) { + if (qobject_cast(QCoreApplication::instance()) == nullptr) { + qCritical() << "Cannot display PlatformMenuEntry as quickshell was not started in " + "QApplication mode."; + qCritical() << "To use platform menus, add `//@ pragma UseQApplication` to the top of your " + "root QML file and restart quickshell."; + return false; + } else if (this->qmenu == nullptr) { qCritical() << "Cannot display PlatformMenuEntry as it is not a menu."; return false; } else if (parentWindow == nullptr) { @@ -113,7 +121,13 @@ bool PlatformMenuEntry::display(QObject* parentWindow, int relativeX, int relati } bool PlatformMenuEntry::display(PopupAnchor* anchor) { - if (!anchor->backingWindow() || !anchor->backingWindow()->isVisible()) { + if (qobject_cast(QCoreApplication::instance()) == nullptr) { + qCritical() << "Cannot display PlatformMenuEntry as quickshell was not started in " + "QApplication mode."; + qCritical() << "To use platform menus, add `//@ pragma UseQApplication` to the top of your " + "root QML file and restart quickshell."; + return false; + } else if (!anchor->backingWindow() || !anchor->backingWindow()->isVisible()) { qCritical() << "Cannot display PlatformMenuEntry on anchor without visible window."; return false; } @@ -140,6 +154,10 @@ bool PlatformMenuEntry::display(PopupAnchor* anchor) { } void PlatformMenuEntry::relayout() { + if (qobject_cast(QCoreApplication::instance()) == nullptr) { + return; + } + if (this->menu->hasChildren()) { delete this->qaction; this->qaction = nullptr; diff --git a/src/core/qsmenuanchor.cpp b/src/core/qsmenuanchor.cpp index e6af7865..8c9b5250 100644 --- a/src/core/qsmenuanchor.cpp +++ b/src/core/qsmenuanchor.cpp @@ -1,5 +1,7 @@ #include "qsmenuanchor.hpp" +#include +#include #include #include #include @@ -15,6 +17,14 @@ namespace qs::menu { QsMenuAnchor::~QsMenuAnchor() { this->onClosed(); } void QsMenuAnchor::open() { + if (qobject_cast(QCoreApplication::instance()) == nullptr) { + qCritical() << "Cannot call QsMenuAnchor.open() as quickshell was not started in " + "QApplication mode."; + qCritical() << "To use platform menus, add `//@ pragma UseQApplication` to the top of your " + "root QML file and restart quickshell."; + return; + } + if (this->mOpen) { qCritical() << "Cannot call QsMenuAnchor.open() as it is already open."; return;