QPA: Fix semantics of GUI event dispatcher ownership in platform plugins

The QPlatformIntegration::guiThreadEventDispatcher() function acted as an
accessor to event dispatchers created in the constructor of each platform
plugin, but the logic and semantics of event-dispatcher handling in Qt
itself (QCoreApplication/QGuiApplication) still assumed both ownership
and control over the event dispatcher, such as when to create one, which
one to create, and when to delete it. This conflicted with the explicit
calls in the platform plugins to QGuiApplication::setEventDispatcher(),
as well as left a possibility that the event-dispatcher created by
the platform plugin would never be deleted, as none of the platform
plugins actually took full ownership of the dispatcher and deleted it
in its destructor.

The integration function has now been renamed back to its old name,
createEventDispatcher(), and acts as a factory function, leaving
the logic and lifetime of event dispatcher to QtCoreApplication.

The only platform left with creating the event-dispatcher in the
constructor is QNX, where other parts of the platform relies on
having an event-dispatcher before their initialization. We then
need to manually take care of the ownership transfer, so that the
event-dispatcher is still destroyed at some point.

Change-Id: I113db97d2545ebda39ebdefa865e488d2ce9368b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Tor Arne Vestbø 2013-09-26 12:14:32 +02:00 committed by The Qt Project
parent a2bf063dd4
commit 999e5162ec
32 changed files with 91 additions and 116 deletions

View File

@ -1029,27 +1029,23 @@ void QGuiApplicationPrivate::createPlatformIntegration()
} }
/*!
Called from QCoreApplication::init()
Responsible for creating an event dispatcher when QCoreApplication
decides that it needs one (because a custom one has not been set).
*/
void QGuiApplicationPrivate::createEventDispatcher() void QGuiApplicationPrivate::createEventDispatcher()
{ {
Q_ASSERT(!eventDispatcher);
if (platform_integration == 0) if (platform_integration == 0)
createPlatformIntegration(); createPlatformIntegration();
if (!eventDispatcher) { // The platform integration should not mess with the event dispatcher
QAbstractEventDispatcher *eventDispatcher = platform_integration->guiThreadEventDispatcher(); Q_ASSERT(!eventDispatcher);
setEventDispatcher(eventDispatcher);
}
}
void QGuiApplicationPrivate::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
{
Q_Q(QGuiApplication);
if (!QCoreApplicationPrivate::eventDispatcher) {
QCoreApplicationPrivate::eventDispatcher = eventDispatcher;
QCoreApplicationPrivate::eventDispatcher->setParent(q);
threadData->eventDispatcher = eventDispatcher;
}
eventDispatcher = platform_integration->createEventDispatcher();
} }
#if defined(QT_DEBUG) && defined(Q_OS_LINUX) #if defined(QT_DEBUG) && defined(Q_OS_LINUX)

View File

@ -83,8 +83,7 @@ public:
~QGuiApplicationPrivate(); ~QGuiApplicationPrivate();
void createPlatformIntegration(); void createPlatformIntegration();
void createEventDispatcher(); void createEventDispatcher() Q_DECL_OVERRIDE;
void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
virtual void notifyLayoutDirectionChange(); virtual void notifyLayoutDirectionChange();
virtual void notifyActiveWindowChange(QWindow *previous); virtual void notifyActiveWindowChange(QWindow *previous);

View File

@ -231,17 +231,23 @@ QPlatformServices *QPlatformIntegration::services() const
are never repositioned by the window manager. The default implementation returns true. are never repositioned by the window manager. The default implementation returns true.
*/ */
/*! /*!
\fn QAbstractEventDispatcher *QPlatformIntegration::guiThreadEventDispatcher() const = 0 \fn QAbstractEventDispatcher *QPlatformIntegration::createEventDispatcher() const = 0
Accessor function for the event dispatcher. The platform plugin should create Factory function for the GUI event dispatcher. The platform plugin should create
an instance of the QAbstractEventDispatcher in its constructor and set it and return a QAbstractEventDispatcher subclass when this function is called.
on the application using QGuiApplicationPrivate::instance()->setEventDispatcher().
The event dispatcher is owned by QGuiApplication, the accessor should return If the platform plugin for some reason creates the event dispatcher outside of
a flat pointer. this function (for example in the constructor), it needs to handle the case
\sa QGuiApplicationPrivate where this function is never called, ensuring that the event dispatcher is
still deleted at some point (typically in the destructor).
Note that the platform plugin should never explicitly set the event dispatcher
itself, using QCoreApplication::setEventDispatcher(), but let QCoreApplication
decide when and which event dispatcher to create.
\since 5.2
*/ */
bool QPlatformIntegration::hasCapability(Capability cap) const bool QPlatformIntegration::hasCapability(Capability cap) const

View File

@ -111,7 +111,7 @@ public:
virtual QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const; virtual QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const;
// Event dispatcher: // Event dispatcher:
virtual QAbstractEventDispatcher *guiThreadEventDispatcher() const = 0; virtual QAbstractEventDispatcher *createEventDispatcher() const = 0;
//Deeper window system integrations //Deeper window system integrations
virtual QPlatformFontDatabase *fontDatabase() const; virtual QPlatformFontDatabase *fontDatabase() const;

View File

@ -100,10 +100,6 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList &para
{ {
Q_UNUSED(paramList); Q_UNUSED(paramList);
#ifndef ANDROID_PLUGIN_OPENGL
m_eventDispatcher = createUnixEventDispatcher();
#endif
m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface(); m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface();
#ifndef ANDROID_PLUGIN_OPENGL #ifndef ANDROID_PLUGIN_OPENGL
@ -150,9 +146,9 @@ QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *wind
return new QAndroidPlatformWindow(window); return new QAndroidPlatformWindow(window);
} }
QAbstractEventDispatcher *QAndroidPlatformIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QAndroidPlatformIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; return createUnixEventDispatcher();
} }
#else // !ANDROID_PLUGIN_OPENGL #else // !ANDROID_PLUGIN_OPENGL
QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const

View File

@ -93,7 +93,7 @@ public:
#ifndef ANDROID_PLUGIN_OPENGL #ifndef ANDROID_PLUGIN_OPENGL
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QAndroidPlatformScreen *screen() { return m_primaryScreen; } QAndroidPlatformScreen *screen() { return m_primaryScreen; }
#else #else
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
@ -147,7 +147,6 @@ private:
QTouchDevice *m_touchDevice; QTouchDevice *m_touchDevice;
#ifndef ANDROID_PLUGIN_OPENGL #ifndef ANDROID_PLUGIN_OPENGL
QAbstractEventDispatcher *m_eventDispatcher;
QAndroidPlatformScreen *m_primaryScreen; QAndroidPlatformScreen *m_primaryScreen;
#endif #endif

View File

@ -108,7 +108,7 @@ public:
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
QPlatformNativeInterface *nativeInterface() const; QPlatformNativeInterface *nativeInterface() const;
@ -130,7 +130,6 @@ public:
private: private:
QScopedPointer<QPlatformFontDatabase> mFontDb; QScopedPointer<QPlatformFontDatabase> mFontDb;
QAbstractEventDispatcher *mEventDispatcher;
QScopedPointer<QPlatformInputContext> mInputContext; QScopedPointer<QPlatformInputContext> mInputContext;
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY

View File

@ -216,7 +216,6 @@ QPixmap QCocoaScreen::grabWindow(WId window, int x, int y, int width, int height
QCocoaIntegration::QCocoaIntegration() QCocoaIntegration::QCocoaIntegration()
: mFontDb(new QCoreTextFontDatabase()) : mFontDb(new QCoreTextFontDatabase())
, mEventDispatcher(new QCocoaEventDispatcher())
, mInputContext(new QCocoaInputContext) , mInputContext(new QCocoaInputContext)
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
, mAccessibility(new QCocoaAccessibility) , mAccessibility(new QCocoaAccessibility)
@ -384,9 +383,9 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi
return new QCocoaBackingStore(window); return new QCocoaBackingStore(window);
} }
QAbstractEventDispatcher *QCocoaIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QCocoaIntegration::createEventDispatcher() const
{ {
return mEventDispatcher; return new QCocoaEventDispatcher;
} }
QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const

View File

@ -61,9 +61,7 @@ QT_BEGIN_NAMESPACE
QDirectFbIntegration::QDirectFbIntegration() QDirectFbIntegration::QDirectFbIntegration()
: m_fontDb(new QGenericUnixFontDatabase()) : m_fontDb(new QGenericUnixFontDatabase())
, m_eventDispatcher(createUnixEventDispatcher())
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
} }
void QDirectFbIntegration::initialize() void QDirectFbIntegration::initialize()
@ -129,9 +127,9 @@ QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWindow *window) con
return dfbWindow; return dfbWindow;
} }
QAbstractEventDispatcher *QDirectFbIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QDirectFbIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; return createUnixEventDispatcher();
} }
QPlatformBackingStore *QDirectFbIntegration::createPlatformBackingStore(QWindow *window) const QPlatformBackingStore *QDirectFbIntegration::createPlatformBackingStore(QWindow *window) const

View File

@ -65,7 +65,7 @@ public:
QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
@ -80,7 +80,6 @@ protected:
QScopedPointer<QDirectFbInput> m_input; QScopedPointer<QDirectFbInput> m_input;
QScopedPointer<QThread> m_inputRunner; QScopedPointer<QThread> m_inputRunner;
QScopedPointer<QPlatformFontDatabase> m_fontDb; QScopedPointer<QPlatformFontDatabase> m_fontDb;
QAbstractEventDispatcher *m_eventDispatcher;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -78,12 +78,9 @@ QT_BEGIN_NAMESPACE
static void *eglContextForContext(QOpenGLContext *context); static void *eglContextForContext(QOpenGLContext *context);
QEglFSIntegration::QEglFSIntegration() QEglFSIntegration::QEglFSIntegration()
: mEventDispatcher(createUnixEventDispatcher()), : mFontDb(new QGenericUnixFontDatabase)
mFontDb(new QGenericUnixFontDatabase), , mServices(new QGenericUnixServices)
mServices(new QGenericUnixServices)
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
#if !defined(QT_NO_EVDEV) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)) #if !defined(QT_NO_EVDEV) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK))
new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this); new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this);
new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this); new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this);
@ -168,9 +165,9 @@ QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const
return mFontDb.data(); return mFontDb.data();
} }
QAbstractEventDispatcher *QEglFSIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QEglFSIntegration::createEventDispatcher() const
{ {
return mEventDispatcher; return createUnixEventDispatcher();
} }
QVariant QEglFSIntegration::styleHint(QPlatformIntegration::StyleHint hint) const QVariant QEglFSIntegration::styleHint(QPlatformIntegration::StyleHint hint) const

View File

@ -67,7 +67,7 @@ public:
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
QPlatformServices *services() const; QPlatformServices *services() const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QVariant styleHint(QPlatformIntegration::StyleHint hint) const; QVariant styleHint(QPlatformIntegration::StyleHint hint) const;
@ -87,7 +87,6 @@ public:
private: private:
EGLDisplay mDisplay; EGLDisplay mDisplay;
QAbstractEventDispatcher *mEventDispatcher;
QScopedPointer<QPlatformFontDatabase> mFontDb; QScopedPointer<QPlatformFontDatabase> mFontDb;
QScopedPointer<QPlatformServices> mServices; QScopedPointer<QPlatformServices> mServices;
QEglFSScreen *mScreen; QEglFSScreen *mScreen;

View File

@ -70,7 +70,7 @@ public:
QStringList themeNames() const; QStringList themeNames() const;
QPlatformTheme *createPlatformTheme(const QString &name) const; QPlatformTheme *createPlatformTheme(const QString &name) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformNativeInterface *nativeInterface() const; QPlatformNativeInterface *nativeInterface() const;
void *nativeResourceForWindow(const QByteArray &resource, QWindow *window); void *nativeResourceForWindow(const QByteArray &resource, QWindow *window);

View File

@ -113,7 +113,7 @@ QPlatformOpenGLContext *QIOSIntegration::createPlatformOpenGLContext(QOpenGLCont
return new QIOSContext(context); return new QIOSContext(context);
} }
QAbstractEventDispatcher *QIOSIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QIOSIntegration::createEventDispatcher() const
{ {
if (isQtApplication()) if (isQtApplication())
return new QIOSEventDispatcher; return new QIOSEventDispatcher;

View File

@ -65,10 +65,8 @@ QT_BEGIN_NAMESPACE
QKmsIntegration::QKmsIntegration() QKmsIntegration::QKmsIntegration()
: QPlatformIntegration(), : QPlatformIntegration(),
m_fontDatabase(new QGenericUnixFontDatabase()), m_fontDatabase(new QGenericUnixFontDatabase()),
m_eventDispatcher(createUnixEventDispatcher()),
m_nativeInterface(new QKmsNativeInterface) m_nativeInterface(new QKmsNativeInterface)
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
setenv("EGL_PLATFORM", "drm",1); setenv("EGL_PLATFORM", "drm",1);
m_vtHandler = new QKmsVTHandler; m_vtHandler = new QKmsVTHandler;
@ -152,9 +150,9 @@ void QKmsIntegration::addScreen(QKmsScreen *screen)
screenAdded(screen); screenAdded(screen);
} }
QAbstractEventDispatcher *QKmsIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QKmsIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; return createUnixEventDispatcher();
} }
QPlatformNativeInterface *QKmsIntegration::nativeInterface() const QPlatformNativeInterface *QKmsIntegration::nativeInterface() const

View File

@ -67,7 +67,7 @@ public:
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformNativeInterface *nativeInterface() const; QPlatformNativeInterface *nativeInterface() const;
@ -84,7 +84,6 @@ private:
QList<QPlatformScreen *> m_screens; QList<QPlatformScreen *> m_screens;
QList<QKmsDevice *> m_devices; QList<QKmsDevice *> m_devices;
QPlatformFontDatabase *m_fontDatabase; QPlatformFontDatabase *m_fontDatabase;
QAbstractEventDispatcher *m_eventDispatcher;
QPlatformNativeInterface *m_nativeInterface; QPlatformNativeInterface *m_nativeInterface;
QKmsVTHandler *m_vtHandler; QKmsVTHandler *m_vtHandler;
QDeviceDiscovery *m_deviceDiscovery; QDeviceDiscovery *m_deviceDiscovery;

View File

@ -54,11 +54,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QLinuxFbIntegration::QLinuxFbIntegration(const QStringList &paramList) QLinuxFbIntegration::QLinuxFbIntegration(const QStringList &paramList)
: m_fontDb(new QGenericUnixFontDatabase()), : m_fontDb(new QGenericUnixFontDatabase())
m_eventDispatcher(createUnixEventDispatcher())
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
m_primaryScreen = new QLinuxFbScreen; m_primaryScreen = new QLinuxFbScreen;
if (m_primaryScreen->initialize(paramList)) if (m_primaryScreen->initialize(paramList))
screenAdded(m_primaryScreen); screenAdded(m_primaryScreen);
@ -92,9 +89,9 @@ QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) cons
return new QFbWindow(window); return new QFbWindow(window);
} }
QAbstractEventDispatcher *QLinuxFbIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QLinuxFbIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; return createUnixEventDispatcher();
} }
QList<QPlatformScreen *> QLinuxFbIntegration::screens() const QList<QPlatformScreen *> QLinuxFbIntegration::screens() const

View File

@ -61,14 +61,13 @@ public:
QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QList<QPlatformScreen *> screens() const; QList<QPlatformScreen *> screens() const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
private: private:
QLinuxFbScreen *m_primaryScreen; QLinuxFbScreen *m_primaryScreen;
QPlatformFontDatabase *m_fontDb; QPlatformFontDatabase *m_fontDb;
QAbstractEventDispatcher *m_eventDispatcher;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -53,14 +53,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QMinimalIntegration::QMinimalIntegration() : QMinimalIntegration::QMinimalIntegration()
#ifdef Q_OS_WIN
m_eventDispatcher(new QEventDispatcherWin32())
#else
m_eventDispatcher(createUnixEventDispatcher())
#endif
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
QMinimalScreen *mPrimaryScreen = new QMinimalScreen(); QMinimalScreen *mPrimaryScreen = new QMinimalScreen();
mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320);
@ -92,9 +86,13 @@ QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *
return new QMinimalBackingStore(window); return new QMinimalBackingStore(window);
} }
QAbstractEventDispatcher *QMinimalIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; #ifdef Q_OS_WIN
return new QEventDispatcherWin32;
#else
return createUnixEventDispatcher();
#endif
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -73,10 +73,7 @@ public:
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
private:
QAbstractEventDispatcher *m_eventDispatcher;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -110,7 +110,7 @@ QPlatformFontDatabase *QMinimalEglIntegration::fontDatabase() const
return mFontDb; return mFontDb;
} }
QAbstractEventDispatcher *QMinimalEglIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QMinimalEglIntegration::createEventDispatcher() const
{ {
return createUnixEventDispatcher(); return createUnixEventDispatcher();
} }

View File

@ -63,7 +63,7 @@ public:
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QVariant styleHint(QPlatformIntegration::StyleHint hint) const; QVariant styleHint(QPlatformIntegration::StyleHint hint) const;

View File

@ -95,14 +95,12 @@ public:
QOffscreenIntegration::QOffscreenIntegration() QOffscreenIntegration::QOffscreenIntegration()
{ {
#if defined(Q_OS_UNIX) #if defined(Q_OS_UNIX)
m_eventDispatcher = createUnixEventDispatcher();
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
m_fontDatabase.reset(new QPlatformFontDatabase()); m_fontDatabase.reset(new QPlatformFontDatabase());
#else #else
m_fontDatabase.reset(new QGenericUnixFontDatabase()); m_fontDatabase.reset(new QGenericUnixFontDatabase());
#endif #endif
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
m_eventDispatcher = new QOffscreenEventDispatcher<QEventDispatcherWin32>();
m_fontDatabase.reset(new QBasicFontDatabase()); m_fontDatabase.reset(new QBasicFontDatabase());
#endif #endif
@ -111,7 +109,6 @@ QOffscreenIntegration::QOffscreenIntegration()
#endif #endif
m_services.reset(new QPlatformServices); m_services.reset(new QPlatformServices);
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
screenAdded(new QOffscreenScreen); screenAdded(new QOffscreenScreen);
} }
@ -141,9 +138,15 @@ QPlatformBackingStore *QOffscreenIntegration::createPlatformBackingStore(QWindow
return new QOffscreenBackingStore(window); return new QOffscreenBackingStore(window);
} }
QAbstractEventDispatcher *QOffscreenIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QOffscreenIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; #if defined(Q_OS_UNIX)
return createUnixEventDispatcher();
#elif defined(Q_OS_WIN)
return new QOffscreenEventDispatcher<QEventDispatcherWin32>();
#else
return 0;
#endif
} }
QPlatformFontDatabase *QOffscreenIntegration::fontDatabase() const QPlatformFontDatabase *QOffscreenIntegration::fontDatabase() const

View File

@ -66,12 +66,11 @@ public:
QPlatformServices *services() const; QPlatformServices *services() const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
static QOffscreenIntegration *createOffscreenIntegration(); static QOffscreenIntegration *createOffscreenIntegration();
private: private:
QAbstractEventDispatcher *m_eventDispatcher;
QScopedPointer<QPlatformFontDatabase> m_fontDatabase; QScopedPointer<QPlatformFontDatabase> m_fontDatabase;
#ifndef QT_NO_DRAGANDDROP #ifndef QT_NO_DRAGANDDROP
QScopedPointer<QPlatformDrag> m_drag; QScopedPointer<QPlatformDrag> m_drag;

View File

@ -63,9 +63,7 @@
QOpenWFDIntegration::QOpenWFDIntegration() QOpenWFDIntegration::QOpenWFDIntegration()
: QPlatformIntegration() : QPlatformIntegration()
, mPrinterSupport(new QGenericUnixPrinterSupport) , mPrinterSupport(new QGenericUnixPrinterSupport)
, mEventDispatcher(createUnixEventDispatcher())
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
int numberOfDevices = wfdEnumerateDevices(0,0,0); int numberOfDevices = wfdEnumerateDevices(0,0,0);
WFDint devices[numberOfDevices]; WFDint devices[numberOfDevices];
@ -119,9 +117,9 @@ QPlatformBackingStore *QOpenWFDIntegration::createPlatformBackingStore(QWindow *
return new QOpenWFDBackingStore(window); return new QOpenWFDBackingStore(window);
} }
QAbstractEventDispatcher *QOpenWFDIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QOpenWFDIntegration::createEventDispatcher() const
{ {
return mEventDispatcher; return createUnixEventDispatcher();
} }
QPlatformFontDatabase *QOpenWFDIntegration::fontDatabase() const QPlatformFontDatabase *QOpenWFDIntegration::fontDatabase() const

View File

@ -62,7 +62,7 @@ public:
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
//This should not be a factory interface, but rather a accessor //This should not be a factory interface, but rather a accessor
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformFontDatabase *fontDatabase() const; QPlatformFontDatabase *fontDatabase() const;
@ -78,7 +78,6 @@ private:
QPlatformFontDatabase *mFontDatabase; QPlatformFontDatabase *mFontDatabase;
QPlatformNativeInterface *mNativeInterface; QPlatformNativeInterface *mNativeInterface;
QPlatformPrinterSupport *mPrinterSupport; QPlatformPrinterSupport *mPrinterSupport;
QAbstractEventDispatcher *mEventDispatcher;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -294,6 +294,9 @@ QQnxIntegration::~QQnxIntegration()
delete m_bpsEventFilter; delete m_bpsEventFilter;
#endif #endif
// In case the event-dispatcher was never transferred to QCoreApplication
delete m_eventDispatcher;
delete m_screenEventHandler; delete m_screenEventHandler;
// Destroy all displays // Destroy all displays
@ -386,10 +389,15 @@ void QQnxIntegration::moveToScreen(QWindow *window, int screen)
platformWindow->setScreen(platformScreen); platformWindow->setScreen(platformScreen);
} }
QAbstractEventDispatcher *QQnxIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QQnxIntegration::createEventDispatcher() const
{ {
qIntegrationDebug() << Q_FUNC_INFO; qIntegrationDebug() << Q_FUNC_INFO;
return m_eventDispatcher;
// We transfer ownersip of the event-dispatcher to QtCoreApplication
QAbstractEventDispatcher *eventDispatcher = m_eventDispatcher;
m_eventDispatcher = 0;
return eventDispatcher;
} }
QPlatformNativeInterface *QQnxIntegration::nativeInterface() const QPlatformNativeInterface *QQnxIntegration::nativeInterface() const

View File

@ -107,7 +107,7 @@ public:
bool supportsNavigatorEvents() const; bool supportsNavigatorEvents() const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
QPlatformFontDatabase *fontDatabase() const { return m_fontDatabase; } QPlatformFontDatabase *fontDatabase() const { return m_fontDatabase; }
@ -158,7 +158,7 @@ private:
#endif #endif
QQnxServices *m_services; QQnxServices *m_services;
QPlatformFontDatabase *m_fontDatabase; QPlatformFontDatabase *m_fontDatabase;
QAbstractEventDispatcher *m_eventDispatcher; mutable QAbstractEventDispatcher *m_eventDispatcher;
#if defined(Q_OS_BLACKBERRY) #if defined(Q_OS_BLACKBERRY)
QQnxBpsEventFilter *m_bpsEventFilter; QQnxBpsEventFilter *m_bpsEventFilter;
#endif #endif

View File

@ -315,7 +315,6 @@ struct QWindowsIntegrationPrivate
QWindowsDrag m_drag; QWindowsDrag m_drag;
# endif # endif
#endif #endif
QWindowsGuiEventDispatcher *m_eventDispatcher;
#if defined(QT_OPENGL_ES_2) #if defined(QT_OPENGL_ES_2)
QEGLStaticContextPtr m_staticEGLContext; QEGLStaticContextPtr m_staticEGLContext;
#elif !defined(QT_NO_OPENGL) #elif !defined(QT_NO_OPENGL)
@ -356,7 +355,6 @@ static inline unsigned parseOptions(const QStringList &paramList)
QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList &paramList) QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList &paramList)
: m_options(parseOptions(paramList)) : m_options(parseOptions(paramList))
, m_fontDatabase(0) , m_fontDatabase(0)
, m_eventDispatcher(new QWindowsGuiEventDispatcher)
{ {
} }
@ -369,7 +367,6 @@ QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate()
QWindowsIntegration::QWindowsIntegration(const QStringList &paramList) : QWindowsIntegration::QWindowsIntegration(const QStringList &paramList) :
d(new QWindowsIntegrationPrivate(paramList)) d(new QWindowsIntegrationPrivate(paramList))
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(d->m_eventDispatcher);
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
d->m_clipboard.registerViewer(); d->m_clipboard.registerViewer();
#endif #endif
@ -635,9 +632,9 @@ QPlatformSessionManager *QWindowsIntegration::createPlatformSessionManager(const
} }
#endif #endif
QAbstractEventDispatcher * QWindowsIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher * QWindowsIntegration::createEventDispatcher() const
{ {
return d->m_eventDispatcher; return new QWindowsGuiEventDispatcher;
} }
QStringList QWindowsIntegration::themeNames() const QStringList QWindowsIntegration::themeNames() const

View File

@ -74,7 +74,7 @@ public:
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
#endif #endif
virtual QAbstractEventDispatcher *guiThreadEventDispatcher() const; virtual QAbstractEventDispatcher *createEventDispatcher() const;
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
virtual QPlatformClipboard *clipboard() const; virtual QPlatformClipboard *clipboard() const;
# ifndef QT_NO_DRAGANDDROP # ifndef QT_NO_DRAGANDDROP

View File

@ -124,12 +124,9 @@ static bool runningUnderDebugger()
#endif #endif
QXcbIntegration::QXcbIntegration(const QStringList &parameters, int &argc, char **argv) QXcbIntegration::QXcbIntegration(const QStringList &parameters, int &argc, char **argv)
: m_eventDispatcher(createUnixEventDispatcher()) : m_services(new QGenericUnixServices)
, m_services(new QGenericUnixServices)
, m_instanceName(0) , m_instanceName(0)
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
#ifdef XCB_USE_XLIB #ifdef XCB_USE_XLIB
XInitThreads(); XInitThreads();
#endif #endif
@ -293,9 +290,9 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
} }
} }
QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const
{ {
return m_eventDispatcher; return createUnixEventDispatcher();
} }
void QXcbIntegration::moveToScreen(QWindow *window, int screen) void QXcbIntegration::moveToScreen(QWindow *window, int screen)

View File

@ -67,7 +67,7 @@ public:
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const;
bool hasCapability(Capability cap) const; bool hasCapability(Capability cap) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *createEventDispatcher() const;
void moveToScreen(QWindow *window, int screen); void moveToScreen(QWindow *window, int screen);
@ -112,7 +112,6 @@ private:
QScopedPointer<QXcbNativeInterface> m_nativeInterface; QScopedPointer<QXcbNativeInterface> m_nativeInterface;
QScopedPointer<QPlatformInputContext> m_inputContext; QScopedPointer<QPlatformInputContext> m_inputContext;
QAbstractEventDispatcher *m_eventDispatcher;
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
QScopedPointer<QPlatformAccessibility> m_accessibility; QScopedPointer<QPlatformAccessibility> m_accessibility;