@@ -366,23 +366,23 @@ static void initGui(GuiApplication* guiApp)
366366 if (!guiApp)
367367 return ;
368368
369- // Retrieve OpenGL infos
370- const std::string strGlVersion = queryGlVersionString ();
371- const QVersionNumber glVersion = parseSemanticVersionString (strGlVersion);
372- qInfo () << fmt::format (" OpenGL v{}.{}" , glVersion.majorVersion (), glVersion.minorVersion ()).c_str ();
373-
374369 // Fallback for OpenGL
375370 setFunctionCreateGraphicsDriver (&QWidgetOccView::createCompatibleGraphicsDriver);
376371 IWidgetOccView::setCreator (&QWidgetOccView::create);
377372
378373 // Use QOpenGLWidget if possible
379374#if OCC_VERSION_HEX >= 0x070600
380- if (!glVersion.isNull () && glVersion.majorVersion () >= 2 ) { // Requires at least OpenGL version >= 2.0
381- setFunctionCreateGraphicsDriver (&QOpenGLWidgetOccView::createCompatibleGraphicsDriver);
382- IWidgetOccView::setCreator (&QOpenGLWidgetOccView::create);
383- }
384- else {
385- qWarning () << " Can't use QOpenGLWidget because OpenGL version is too old" ;
375+ if (qobject_cast<QGuiApplication*>(QCoreApplication::instance ())) { // QOpenGL requires QGuiApplication
376+ const std::string strGlVersion = queryGlVersionString ();
377+ const QVersionNumber glVersion = parseSemanticVersionString (strGlVersion);
378+ qInfo () << fmt::format (" OpenGL v{}.{}" , glVersion.majorVersion (), glVersion.minorVersion ()).c_str ();
379+ if (!glVersion.isNull () && glVersion.majorVersion () >= 2 ) { // Requires at least OpenGL version >= 2.0
380+ setFunctionCreateGraphicsDriver (&QOpenGLWidgetOccView::createCompatibleGraphicsDriver);
381+ IWidgetOccView::setCreator (&QOpenGLWidgetOccView::create);
382+ }
383+ else {
384+ qWarning () << " Can't use QOpenGLWidget because OpenGL version is too old" ;
385+ }
386386 }
387387#endif
388388
0 commit comments