I had this problem, and I needed to call the XSync
method as shown below. This is part of a OgreWidget::initialize
method, where OgreWidget
subclasses QWidget
. initialize
is called as part of construction of OgreWidget
, after m_OgreRoot
is allocated and the render system is set.
setAttribute(Qt::WA_PaintOnScreen, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setFocusPolicy(Qt::StrongFocus);
Ogre::String winHandle;
QX11Info info = x11Info();
winHandle = Ogre::StringConverter::toString((unsigned long)(info.display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));
Ogre::NameValuePairList params;
params["parentWindowHandle"] = winHandle;
params["FSAA"] = Ogre::String("8");
int w = width();
int h = height();
// Need to call XSync or the window handles will be invalid.
XSync(info.display(), False);
m_OgreWindow =
m_OgreRoot->createRenderWindow("OgreWidget_RenderWindow",
qMax(w, 640), qMax(h, 480), false, ¶ms);
Here is the same code modified for Qt 5.1.0. QX11Info
was removed for Qt 5.0.x, then added to the "extras" component for Qt 5.1.0. The new QX11Info
class has only static methods.
#include <QtX11Extras/QX11Info>
...
setAttribute(Qt::WA_PaintOnScreen, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setFocusPolicy(Qt::StrongFocus);
Ogre::String winHandle;
winHandle = Ogre::StringConverter::toString((unsigned long)(QX11Info::display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(QX11Info::appScreen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));
Ogre::NameValuePairList params;
params["parentWindowHandle"] = winHandle;
params["FSAA"] = Ogre::String("8");
int w = width();
int h = height();
// Need to call XSync or the window handles will be invalid.
XSync(QX11Info::display(), False);
m_OgreWindow =
m_OgreRoot->createRenderWindow("OgreWidget_RenderWindow",
qMax(w, 640), qMax(h, 480), false, ¶ms);