我有這個問題,我需要調用XSync
方法如下所示。這是OgreWidget::initialize
方法的一部分,其中OgreWidget
的子類QWidget
。在分配m_OgreRoot
並設置了渲染系統之後,initialize
被稱爲OgreWidget
的構造的一部分。
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);
這裏是爲Qt 5.1.0修改的相同的代碼。爲Qt 5.0.x刪除了QX11Info
,然後添加到Qt 5.1.0的「extras」組件中。新的QX11Info
類只有靜態方法。
#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);