Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can't enable debug context for QQmlApplicationEngine
Forum Updated to NodeBB v4.3 + New Features

Can't enable debug context for QQmlApplicationEngine

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
opengl
1 Posts 1 Posters 706 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Stefan Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved