Qt World Summit: Submit your Presentation

Can't enable debug context for QQmlApplicationEngine

  • I want to enable OpenGL logging in Qt. My code:


    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QSurfaceFormat>
    #include <QOpenGLContext>
    #include <QOpenGLDebugLogger>
    QSurfaceFormat createSurfaceFormat() {
        QSurfaceFormat format;
        return format;
    void initGLLogging(QQmlApplicationEngine& engine) {
        QOpenGLContext *ctx = QOpenGLContext::currentContext();
        QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(&engine);
        qDebug() << "can gl log? " << ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug"));
        QObject::connect(logger, &QOpenGLDebugLogger::messageLogged,
            [&](const QOpenGLDebugMessage &debugMessage) {
                qDebug() << debugMessage;
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        return app.exec();


    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 640
        height: 480

    The output, after building in debug mode and running in the debugger, is:

    QOpenGLDebugLogger::initialize(): the current context is not a debug context:
        this means that the GL may not generate any debug output at all.
        To avoid this warning, try creating the context with the
        QSurfaceFormat::DebugContext surface format option.
    can gl log?  true

    Any idea why it's failing?

    Note: I'm using ANGLE-mode in all Qt apps on my system, enabled via an env var, because otherwise they break in all kinds of ways. That's very likely to be related to the problem, but I can't do without this setting.

Log in to reply