Skip to content

Commit 5ac9174

Browse files
committed
Qt6 - force QT_QPA_PLATFORM=xcb on Linux to run Xlib platform plugin compatible with OCCT
1 parent fba4fcb commit 5ac9174

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

occt-qopenglwidget/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QSlider>
1717
#include <Standard_WarningsRestore.hxx>
1818

19+
#include <OSD_Environment.hxx>
1920
#include <Standard_Version.hxx>
2021

2122
//! Main application window.
@@ -166,6 +167,23 @@ class MyMainWindow : public QMainWindow
166167

167168
int main(int theNbArgs, char** theArgVec)
168169
{
170+
#if defined(_WIN32)
171+
//
172+
#elif defined(__APPLE__)
173+
//
174+
#else
175+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
176+
// Qt6 tries to use Wayland platform by default, which is incompatible with OCCT depending on Xlib;
177+
// Force 'xcb' platform plugin (alternatively, could be passed QApplication as '-platfom xcb' argument).
178+
OSD_Environment aQpaPlat("QT_QPA_PLATFORM");
179+
if (aQpaPlat.Value().IsEmpty())
180+
{
181+
aQpaPlat.SetValue("xcb");
182+
aQpaPlat.Build();
183+
}
184+
#endif
185+
#endif
186+
169187
QApplication aQApp(theNbArgs, theArgVec);
170188

171189
QCoreApplication::setApplicationName("OCCT Qt/QOpenGLWidget Viewer sample");

occt-qwidget/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QSlider>
1717
#include <Standard_WarningsRestore.hxx>
1818

19+
#include <OSD_Environment.hxx>
1920
#include <Standard_Version.hxx>
2021

2122
//! Main application window.
@@ -168,6 +169,23 @@ class MyMainWindow : public QMainWindow
168169

169170
int main(int theNbArgs, char** theArgVec)
170171
{
172+
#if defined(_WIN32)
173+
//
174+
#elif defined(__APPLE__)
175+
//
176+
#else
177+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
178+
// Qt6 tries to use Wayland platform by default, which is incompatible with OCCT depending on Xlib;
179+
// Force 'xcb' platform plugin (alternatively, could be passed QApplication as '-platfom xcb' argument).
180+
OSD_Environment aQpaPlat("QT_QPA_PLATFORM");
181+
if (aQpaPlat.Value().IsEmpty())
182+
{
183+
aQpaPlat.SetValue("xcb");
184+
aQpaPlat.Build();
185+
}
186+
#endif
187+
#endif
188+
171189
QApplication aQApp(theNbArgs, theArgVec);
172190

173191
QCoreApplication::setApplicationName("OCCT Qt/QWidget Viewer sample");

0 commit comments

Comments
 (0)