无法为QQmlApplicationEngine启用调试上下文

时间:2017-03-20 13:59:22

标签: qt opengl qml qtquick2

我想在Qt中启用OpenGL日志记录。我的代码:

的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
}

在调试模式下构建并在调试器中运行后,输出为:

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

知道为什么会失败吗?

注意:我在我的系统上的所有Qt应用程序中使用ANGLE模式,通过env var启用,因为否则它们会以各种方式中断。这很可能与问题有关,但我不能没有这个设置。

0 个答案:

没有答案