Check that QPlatformIntegration::createPlatformWindow() doesn't fail

We expect createPlatformWindow() to return a valid platform window. If
it fails we now assert in debug, and emit a warning in release. The only
platform where this is currently possible is on Windows, where the
platform plugin will return 0 if CreateWindowEx for some reason fails.

Change-Id: Ia2461efcfc48d180e073fa372d9c385650129e1c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
bb10
Tor Arne Vestbø 2015-10-16 14:40:53 +02:00
parent c63f4c5d01
commit 40b4c305d8
1 changed files with 22 additions and 16 deletions

View File

@ -389,25 +389,31 @@ void QWindowPrivate::setTopLevelScreen(QScreen *newScreen, bool recreate)
void QWindowPrivate::create(bool recursive)
{
Q_Q(QWindow);
if (!platformWindow) {
platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q);
QObjectList childObjects = q->children();
for (int i = 0; i < childObjects.size(); i ++) {
QObject *object = childObjects.at(i);
if (object->isWindowType()) {
QWindow *window = static_cast<QWindow *>(object);
if (recursive)
window->d_func()->create(true);
if (window->d_func()->platformWindow)
window->d_func()->platformWindow->setParent(platformWindow);
}
}
if (platformWindow)
return;
if (platformWindow) {
QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
QGuiApplication::sendEvent(q, &e);
platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q);
Q_ASSERT(platformWindow);
if (!platformWindow) {
qWarning() << "Failed to create platform window for" << q << "with flags" << q->flags();
return;
}
QObjectList childObjects = q->children();
for (int i = 0; i < childObjects.size(); i ++) {
QObject *object = childObjects.at(i);
if (object->isWindowType()) {
QWindow *window = static_cast<QWindow *>(object);
if (recursive)
window->d_func()->create(true);
if (window->d_func()->platformWindow)
window->d_func()->platformWindow->setParent(platformWindow);
}
}
QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
QGuiApplication::sendEvent(q, &e);
}
void QWindowPrivate::clearFocusObject()