Skip to content
Apr 27 / kkrizka

Custom GL/DirectX QWidget Problems With Qt 4.4

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.

3 Comments

Leave a comment
  1. lukrop / Jul 4 2008

    hi,

    may you share the code with us?
    I want to build a (open source) irrlicht editor with qt. šŸ˜‰

    cheers!

  2. strelok / Feb 21 2010

    You were wrong. Stipulates the need of another attribute is Qt::WA_NoSystemBackground

    test::test(QWidget *parent, Qt::WFlags flags)
    : QWidget(parent, flags)
    {
    setAttribute(Qt::WA_NoSystemBackground);
    }

  3. Fred Pauling / Apr 4 2011

    Hi Karol, Thanks for your QtIrrlictWidget code in various places on the web.

    I am currently trying to use it under Qt4.7/Irrlict1.7/Ubuntu10.04 but have run into the same errors you flagged above. It looks like the winId is wrong from Qt. Do you have an updated link to your code that might work for this setup?

    Cheers,

    Fred.

Leave a comment
Cancel reply