Custom GL/DirectX QWidget Problems With Qt 4.4
Karol Krizka @ April 27, 2008
Programming
I spent the better part of Friday trying to use Irrlicht to draw 3D scenes in a Qt widget. The code that was sent to me worked perfectly with Qt 4.3, but crashed with a landslide of errors when I compiled Qt 4.4-rc1:
Linux 2.6.18-8.1.3.el5 #1 SMP Mon Apr 30 14:15:37 EDT 2007 i686
Creating X window…
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: GLXBadDrawable
Could not make context current.
XErrorEvent: BadDrawable (invalid Pixmap or Window parameter)
XErrorEvent: BadWindow (invalid Window parameter)
XErrorEvent: BadDrawable (invalid Pixmap or Window parameter)
XErrorEvent: BadDrawable (invalid Pixmap or Window parameter)
Using renderer: OpenGL
Segmentation fault
The code used tried to draw to an existing QWidget by passing the window id (QWidget::winId()) to irrlicht (supported in latest SVN) and creating a context around it. However Qt 4.4 started returning invalid window id’s for some reason. After a bit of hacking, I managed to get the code working perfectly with a QGLWidget, but that had a lot of extraneous features that I did not need (they are provided by irrlicht) and compability with DirectX was in question. After a bit of investigation of the difference between QWidgets and QGLWidgets, I found the following piece of code in the constructor of QGLWidget:
setAttribute(Qt::WA_PaintOnScreen)
This attribute is supposed to allow other libraries to draw into the QWidget, but seemingly it is no longer turned on by default in Qt 4.4. So I tried to put it into the constructor of my irrlichted QWidget and everything worked!
So if you are trying to draw using an exernal library into a QWidget, make sure that WA_PaintOnScreen is turned on by placing the above mentioned code into the constructor.
Did you enjoy this post? Then why not subscribe to my RSS feed or subscribe by e-mail? Also check out the many other FREE ways to appreciate a blogger.
My name is Karol Krizka, and I am a undergraduate student at SFU where I study physics and computer science. In my free time, I write simple applications and play with my PSP.
hi,
may you share the code with us?
I want to build a (open source) irrlicht editor with qt.
cheers!