I'm using Irrlicht in a Qt context. To do this, I have an IrrlichtWidget
class which shows an Irrlicht device in a QWidget. Here is the relevant part of that class:
class IrrlichtWidget : public QWidget{
Q_OBJECT
public:
IrrlichtWidget(){
irr::SIrrlichtCreationParameters params;
params.DriverType = irr::video::EDT_OPENGL;
params.WindowId = (void*)winId();
m_device = irr::createDeviceEx(params);
setAttribute(Qt::WA_OpaquePaintEvent);
m_timer = new QTimer;
m_timer->setInterval(0);
QObject::connect(m_timer, &QTimer::timeout, [this](){
m_device->getVideoDriver()->beginScene(true, true, irr::video::SColor(255, 255, 255, 255));
m_device->getSceneManager()->drawAll();
m_device->getVideoDriver()->endScene();
m_device->run();
});
m_timer->start();
}
private:
irr::IrrlichtDevice *m_device;
QTimer *m_timer;
}
This works just fine until I use a QMessageBox
. When I was programming with this class and wanted to use a QMessageBox
, I noticed that whenever the message box opened, the Irrlicht widget turned black. To try to find out what was going on, I inserted a QMessageBox
in the Irrlicht main loop so that it looked like this:
QObject::connect(m_timer, &QTimer::timeout, [this](){
m_device->getVideoDriver()->beginScene(true, true, irr::video::SColor(255, 255, 255, 255));
m_device->getSceneManager()->drawAll();
m_device->getVideoDriver()->endScene();
m_device->run();
QMessageBox::information(this, "Foo", "Bar");
});
When I did this, the background was black:
To compare, here is exactly the same program with the only difference that it doesn't have a QMessageBox
in it:
I tried putting the QMessageBox
everywhere in Irrlicht's main loop, at the beginning, at the end, in the middle, and it always does the same thing. It does this for every kind of Qt dialog boxes: QMessageBox
, QFileDialog
, etc.
I also tried removing the setAttribute(Qt::WA_OpaquePaintEvent)
line in the constructor, and then the background was beige instead of black. Not the same color, but still the same problem.
It seems like the QMessageBox
is somehow erasing the content of the Irrlicht widget. Why is it doing this? How can I fix it?