Provide a native interface instance in minimal platform plugin

The minimal platform plugin does not have any native APIs it could offer
through that interface, but needs to provide an instance anyway. A lot
of code within Qt assumes that a native interface is always available
and does not check the pointer value, which leads to segfaults when used
with the minimal plugin.

Pick-to: 6.4 6.3 6.2 5.15
Change-Id: I625bd95afd49872cff3a34b29ceb0ffbbcd39db7
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Jaroslaw Kubik 2022-07-02 01:03:43 +02:00
parent 64b84977eb
commit e16f742479
2 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformwindow.h>
#include <qpa/qwindowsysteminterface.h>
@ -157,6 +158,13 @@ QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const
#endif
}
QPlatformNativeInterface *QMinimalIntegration::nativeInterface() const
{
if (!m_nativeInterface)
m_nativeInterface.reset(new QPlatformNativeInterface);
return m_nativeInterface.get();
}
QMinimalIntegration *QMinimalIntegration::instance()
{
return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration());

View File

@ -7,6 +7,8 @@
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformscreen.h>
#include <qscopedpointer.h>
QT_BEGIN_NAMESPACE
class QMinimalScreen : public QPlatformScreen
@ -46,12 +48,15 @@ public:
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override;
QAbstractEventDispatcher *createEventDispatcher() const override;
QPlatformNativeInterface *nativeInterface() const override;
unsigned options() const { return m_options; }
static QMinimalIntegration *instance();
private:
mutable QPlatformFontDatabase *m_fontDatabase;
mutable QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
QMinimalScreen *m_primaryScreen;
unsigned m_options;
};