Fix crash when no QApplication is available.

This happens when QtCreator launches qmlplugindump.
Testcase: qmlplugindump -nonrelocatable org.kde.analitza 1.1
or qmlplugindump -nonrelocatable org.kde.okular 2.0

REVIEW: 128767
This commit is contained in:
David Faure 2016-08-26 09:01:21 +02:00
parent 910e6a4ef7
commit a940089a8f

View File

@ -19,6 +19,7 @@
#include "qmenu.h"
#include <QApplication>
#include <QDebug>
#include <QQuickWindow>
#include <QQuickItem>
@ -27,15 +28,18 @@
#include "plasmacomponentsplugin.h"
QMenuProxy::QMenuProxy(QObject *parent)
: QObject(parent),
m_menu(Q_NULLPTR),
m_status(DialogStatus::Closed),
m_placement(Plasma::Types::LeftPosedTopAlignedPopup)
{
m_menu = new QMenu(0);
connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered);
connect(m_menu, &QMenu::aboutToHide, [ = ]() {
m_status = DialogStatus::Closed;
emit statusChanged();
});
if (qobject_cast<QApplication *>(QCoreApplication::instance())) {
m_menu = new QMenu(0);
connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered);
connect(m_menu, &QMenu::aboutToHide, [ = ]() {
m_status = DialogStatus::Closed;
emit statusChanged();
});
}
}
QMenuProxy::~QMenuProxy()
@ -105,6 +109,9 @@ void QMenuProxy::setVisualParent(QObject *parent)
QWindow *QMenuProxy::transientParent()
{
if (!m_menu) {
return Q_NULLPTR;
}
return m_menu->windowHandle()->transientParent();
}