diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-02-20 16:14:45 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-21 16:29:07 +0100 |
commit | bbf1ec42e5875a6e8145211348e509690a30d0a5 (patch) | |
tree | b2a50ccea52dcff9bb5e13e3ffad914eed45ff2f /src/quick/scenegraph/qsgwindowsrenderloop.cpp | |
parent | 3eb56ecb7776fa106d1fb6e43355e2c1bf5c1d0c (diff) |
Add an error signal to QQuickWindow
When nothing is connected to this signal, an error will be printed or,
in case of Windows, a message box will be shown. If there is something
connected, it is up to the application to handle the error.
[ChangeLog] Added a new sceneGraphError() signal to QQuickWindow
which applications can use to detect errors like OpenGL context creation
failures and react in their own custom ways.
Task-number: QTBUG-36138
Change-Id: I33b1e5e0e3f25872af67c5bb5ae937e3470b25f3
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/quick/scenegraph/qsgwindowsrenderloop.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgwindowsrenderloop.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp index 204a303d2c..8af0401478 100644 --- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp +++ b/src/quick/scenegraph/qsgwindowsrenderloop.cpp @@ -42,6 +42,7 @@ #include "qsgwindowsrenderloop_p.h" #include <QtCore/QCoreApplication> +#include <QtCore/QLibraryInfo> #include <QtGui/QScreen> #include <QtGui/QGuiApplication> @@ -182,9 +183,35 @@ void QSGWindowsRenderLoop::show(QQuickWindow *window) m_gl->setShareContext(QSGContext::sharedOpenGLContext()); bool created = m_gl->create(); if (!created) { - qWarning("QtQuick: failed to create OpenGL context"); + const bool isDebug = QLibraryInfo::isDebugBuild(); + QString eglLibName = QLatin1String(isDebug ? "libEGLd.dll" : "libEGL.dll"); + QString glesLibName = QLatin1String(isDebug ? "libGLESv2d.dll" : "libGLESv2.dll"); + QString contextType = QLatin1String(QOpenGLFunctions::isES() ? "EGL" : "OpenGL"); + const char *msg = QT_TRANSLATE_NOOP( + "QSGWindowsRenderLoop", + "Failed to create %1 context. " + "This is most likely caused by not having the necessary graphics drivers installed.\n\n" + "Install a driver providing OpenGL 2.0 or higher, or, if this is not possible, " + "make sure the Angle Open GL ES 2.0 emulation libraries (%2, %3 and d3dcompiler_*.dll) " + "are available in the application executable's directory or in a location listed in PATH."); + QString translatedMsg = tr(msg).arg(contextType).arg(eglLibName).arg(glesLibName); + QString nonTranslatedMsg = QString(QLatin1String(msg)).arg(contextType).arg(eglLibName).arg(glesLibName); + // If there is a slot connected to the error signal, emit it and leave it to + // the application to do something with the message. If nothing is connected, + // show a message on our own and terminate. + bool signalEmitted = QQuickWindowPrivate::get(window)->emitError(QQuickWindow::ContextNotAvailable, + translatedMsg); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) + if (!signalEmitted && !isDebug && !GetConsoleWindow()) { + MessageBox(0, (LPCTSTR) translatedMsg.utf16(), + (LPCTSTR)(QCoreApplication::applicationName().utf16()), + MB_OK | MB_ICONERROR); + } +#endif // !Q_OS_WINCE && !Q_OS_WINRT delete m_gl; m_gl = 0; + if (!signalEmitted) + qFatal("%s", qPrintable(nonTranslatedMsg)); return; } QSG_RENDER_TIMING_SAMPLE(time_created); |