core/menu: opening platform menus w/o QApplication no longer crashes

An error is displayed instead.
This commit is contained in:
outfoxxed 2024-08-16 16:47:50 -07:00
parent 1d2bf5d7b4
commit f89c504b55
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 30 additions and 2 deletions

View file

@ -1,5 +1,7 @@
#include "qsmenuanchor.hpp"
#include <qapplication.h>
#include <qcoreapplication.h>
#include <qlogging.h>
#include <qobject.h>
#include <qtmetamacros.h>
@ -15,6 +17,14 @@ namespace qs::menu {
QsMenuAnchor::~QsMenuAnchor() { this->onClosed(); }
void QsMenuAnchor::open() {
if (qobject_cast<QApplication*>(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;