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. Failure Creating QOpenGLContext in Console Based Application
QtWS25 Last Chance

Failure Creating QOpenGLContext in Console Based Application

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 471 Views
  • 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.
  • B Offline
    B Offline
    Burkules
    wrote on last edited by
    #1

    Hello,
    My team in currently working on an application which renders an OpenGL geometry off-screen to create a bitmap. When executing this code when our application is running with a QML gui everything works as expected.

    However, we are currently developing Google Test, and need to unit test this functionality. Obviously with Google Test there is no GUI, and instead we are just exercising this code through a console -- this is where the issues occurring. When running the following code through google test we get an exception.

    QSurfaceFormat format;
                format.setDepthBufferSize(MinDepthBufferSize);
                format.setStencilBufferSize(StencilBufferSize);
    
                context = make_unique<QOpenGLContext>();
                context->setFormat(format);
                context->create();
    

    The read access exception occurs on 'context->create();'. Documentation on the topic of running a headless OpenGL Qt application is scarce, but everything I found suggests this isn't an issue. I've seen several postings stating that settings in the .pro to run in terminal (i.e. QT -= gui) may be causing OPENGL to not be loaded; but with or without that line I still see the same issue.

    Any help would be appreciated. Thanks!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Burkules
      wrote on last edited by
      #4

      Ah ha! Simple creating an instance of QGuiApplication at the beginning of my test has appeared to resolve this problem, at least. Thank you for the help!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        How are you writing your tests ?

        Are you creating at least a QGuiApplication in your tests ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • B Offline
          B Offline
          Burkules
          wrote on last edited by
          #3

          No, I am not creating a QGuiApplication , which sounds like that might be the issue...

          My team already had gtest framework in place, so I was hoping to piggy back off of that.

          Simply I've just been running:

          int main(int argc, char *argv[])
          {
              ::testing::InitGoogleTest(&argc, argv);
              return RUN_ALL_TESTS();
          }
          
          TEST(PEGTestCase, PEGTestSet)
          {
              QObjectToTest object = new QObjectToTest();
              int qty = object->GetZero();
              EXPECT_EQ(qty, 0);
              ASSERT_THAT(0, Eq(0));
          }
          

          The objects I've been initializing have been QObjects, and things have been working well thus far. Of course they have not had any GUI components, which would explain my need for not needing a QGuiApplication.

          Is it possible to integrate a QGuiApplication into this setup you could point me towards, or am I looking at using QTest to solve this issue? Thank you!

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Burkules
            wrote on last edited by
            #4

            Ah ha! Simple creating an instance of QGuiApplication at the beginning of my test has appeared to resolve this problem, at least. Thank you for the help!

            1 Reply Last reply
            0

            • Login

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