Results 1 to 7 of 7

Thread: QGLWidget doesn't paint when I add another data member

  1. #1
    Join Date
    Oct 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGLWidget doesn't paint when I add another data member

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    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?

  3. #3
    Join Date
    Oct 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    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.

  4. #4
    Join Date
    Oct 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    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.
    Attached Files Attached Files

  5. #5
    Join Date
    Oct 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    Bump. Just trying to get someone's attention.

  6. #6
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    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.

  7. #7
    Join Date
    Oct 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget doesn't paint when I add another data member

    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.

Similar Threads

  1. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06
  2. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.