44
55#include < qaction.h>
66#include < qactiongroup.h>
7+ #include < qapplication.h>
78#include < qcontainerfwd.h>
9+ #include < qcoreapplication.h>
810#include < qicon.h>
911#include < qlogging.h>
1012#include < qmenu.h>
@@ -74,7 +76,13 @@ void PlatformMenuEntry::registerCreationHook(std::function<void(PlatformMenuQMen
7476bool PlatformMenuEntry::display (QObject* parentWindow, int relativeX, int relativeY) {
7577 QWindow* window = nullptr ;
7678
77- if (this ->qmenu == nullptr ) {
79+ if (qobject_cast<QApplication*>(QCoreApplication::instance ()) == nullptr ) {
80+ qCritical () << " Cannot display PlatformMenuEntry as quickshell was not started in "
81+ " QApplication mode." ;
82+ qCritical () << " To use platform menus, add `//@ pragma UseQApplication` to the top of your "
83+ " root QML file and restart quickshell." ;
84+ return false ;
85+ } else if (this ->qmenu == nullptr ) {
7886 qCritical () << " Cannot display PlatformMenuEntry as it is not a menu." ;
7987 return false ;
8088 } else if (parentWindow == nullptr ) {
@@ -113,7 +121,13 @@ bool PlatformMenuEntry::display(QObject* parentWindow, int relativeX, int relati
113121}
114122
115123bool PlatformMenuEntry::display (PopupAnchor* anchor) {
116- if (!anchor->backingWindow () || !anchor->backingWindow ()->isVisible ()) {
124+ if (qobject_cast<QApplication*>(QCoreApplication::instance ()) == nullptr ) {
125+ qCritical () << " Cannot display PlatformMenuEntry as quickshell was not started in "
126+ " QApplication mode." ;
127+ qCritical () << " To use platform menus, add `//@ pragma UseQApplication` to the top of your "
128+ " root QML file and restart quickshell." ;
129+ return false ;
130+ } else if (!anchor->backingWindow () || !anchor->backingWindow ()->isVisible ()) {
117131 qCritical () << " Cannot display PlatformMenuEntry on anchor without visible window." ;
118132 return false ;
119133 }
@@ -140,6 +154,10 @@ bool PlatformMenuEntry::display(PopupAnchor* anchor) {
140154}
141155
142156void PlatformMenuEntry::relayout () {
157+ if (qobject_cast<QApplication*>(QCoreApplication::instance ()) == nullptr ) {
158+ return ;
159+ }
160+
143161 if (this ->menu ->hasChildren ()) {
144162 delete this ->qaction ;
145163 this ->qaction = nullptr ;
0 commit comments