Can't enable debug context for QQmlApplicationEngine



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

    main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QSurfaceFormat>
    #include <QOpenGLContext>
    #include <QOpenGLDebugLogger>
    
    QSurfaceFormat createSurfaceFormat() {
        QSurfaceFormat format;
    
        format.setDepthBufferSize(24);
        format.setStencilBufferSize(8);
        format.setOption(QSurfaceFormat::DebugContext);
        
        return format;
    }
    
    void initGLLogging(QQmlApplicationEngine& engine) {
        QOpenGLContext *ctx = QOpenGLContext::currentContext();
        QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(&engine);
        logger->initialize();
        qDebug() << "can gl log? " << ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug"));
        QObject::connect(logger, &QOpenGLDebugLogger::messageLogged,
            [&](const QOpenGLDebugMessage &debugMessage) {
                qDebug() << debugMessage;
            }
        );
        logger->startLogging();
    }
    
    int main(int argc, char *argv[])
    {
        QSurfaceFormat::setDefaultFormat(::createSurfaceFormat());
        
        QGuiApplication app(argc, argv);
        
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        ::initGLLogging(engine);
        
        return app.exec();
    }
    

    main.qml:

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.