PDA

View Full Version : QGLWidget doesn't paint when I add another data member



Thoughtjacked
15th October 2007, 20:22
I wrote a class that inherits from QGLWidget, and it worked fine when I initially wrote it.

However, suppose I add another data member to the class, like "int foo;". When I run my program, I am just greeted by a black window (since black is the clear color).

I wanted to see what was going on in paintEvent (if it was even firing), so I added another data member ("ofstream foo2"), and printed messages out it. Unfortunately, when I add this data member in addition to the int, everything renders fine again.

I can provide more details if necessary.

marcel
15th October 2007, 20:26
That doesn't make much sense. I mean, you could add a whole lot of class members. As long as they are not used incorrectly in the paintEvent, then they shouldn't interfere.

Are you sure the member doesn't have the same name as a static variable, or as a local paintEvent var and they get mixed up?

Thoughtjacked
15th October 2007, 21:20
Yes, I am sure that there are no static members with the same name as the newly introduced data member. The name of the class member doesn't matter at all in causing the error.

What I have determined is that the datatype matters. If I add a pointer or int to the class, nothing renders. However, if I add an ofstream, things proceed as planned.

I can send you the relevant portion of this code if you don't mind (for Linux or Windows). It uses GLEW, so you would need that installed.

Thoughtjacked
16th October 2007, 01:40
Here is a zip archive containing the code I am talking about. If you uncomment the ofstream declaration in ShaderDemo.h, things display again.

What should display is a spinning red rounded rectangle.

Thoughtjacked
16th October 2007, 19:28
Bump. Just trying to get someone's attention.

ntp
16th October 2007, 22:19
I took a very quick look and the first thing that I noticed is that you are missing the paintGL()
method. I see that you are doing the paint through a paint event but I think you have to have a paintGL as that gets called from the internals.

I would move your paint code into paintGL and see if that works. I don't use the paintEvent but I have seen code where both the paintGL and paintEvent exist so if there is information that you want to capture from the paintEvent, you can have both but the drawing should be done in paintGL.

Though none of this really explains why the code would have been working before.

Thoughtjacked
17th October 2007, 15:45
I am a dummy. I didn't initialize the rotation data member, which meant that sometimes, it would be initialized to garbage and rotate out of view.