Question

I am working on an application that currently uses QWidgets for rendering moving images, and I am trying to move from using QWidgets to QGlWidgets, but my application keeps crashing. The only modifications I've done are:

from this:

class MyClass : public QWidget 
{
     MyClass(QWidget *parent):QWidget(parent)
     {
          ...
     }
}

to this:

class MyClass : public QGlWidget 
{
     MyClass(QWidget *parent):QGlWidget(QGLFormat(QGL::SampleBuffers),parent)
     {
          ...
     }
}

Do I have to modify my code more, if so what other modifications are needed?

I am currently using Visual studio 2010, and qt 4.8.0

Was it helpful?

Solution 2

I found what the problem was. In my QWidget class I had a member object QPainter, that I would reuse in the paint event. I kept searching and found that this is a bad practice, so now I declared a QPainter object at the beginning of the paint event and my problem is solved.

OTHER TIPS

MyClass(QWidget *parent):QGlWidget(QGLFormat(QGL::SampleBuffers),parent)
     {
          ...
     }

It looks like you're creating a temporary QGLFormat object, which is being passed by reference to QGLWidget, and when that temporary object goes out of scope, you'll have an invalid reference.

I would use a different form of the constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top