OpenGL context and testing with catch2



  • I'am trying to test my class that uses QOpenGLTexture but it cannot use QOpenGLTexture becouse there is no OpenGL context. I tried this:

    
    // gui app
        char *dummyArgv[] = {"dummy program name", NULL};
        int dummyArgc = sizeof(dummyArgv) / sizeof(char*) - 1;
        QGuiApplication app(dummyArgc, dummyArgv);
    
    // try 1 
        const auto screens = QGuiApplication::screens();
        REQUIRE(screens.size() > 0);
        QOpenGLContext context;
        context.setScreen(screens[0]);
        REQUIRE(context.create());
        REQUIRE(context.isValid());
    
    // try 2
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/window.qml")));
    
    // try 3
        QQuickView *view = new QQuickView;
        view->setSource(QUrl(QStringLiteral("qrc:/rect.qml")));
        view->show();
    
    

    but I get

    Requires a valid current OpenGL context.
    Texture has not been created
    

    all the time.
    Is there a valid way to create a OpenGL context for QOpenGL-classes without running event loop?


Log in to reply
 

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