Results 1 to 2 of 2

Thread: Segfault openGL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Segfault openGL

    Hello. I am trying to write a program that uses openGL. I create a subclass of the QGLWidget class, and then run it in my main program. Here is my header file for the subclass:

    Qt Code:
    1. #ifndef GLWIDGET_H
    2. #define GLWIDGET_H
    3. #include <QGLWidget>
    4. #include <QtOpenGL>
    5.  
    6. class GLWidget : public QGLWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. GLWidget(QWidget *parent = 0);
    12. void initializeGL();
    13. void paintGL();
    14. };
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Here is the implementation file:

    Qt Code:
    1. #include <QtGui>
    2. #include <QGLWidget>
    3. #include <QtOpenGL>
    4. #include "glwidget.h"
    5.  
    6. GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
    7. {
    8. initializeGL();
    9. paintGL();
    10. }
    11.  
    12. void GLWidget::initializeGL()
    13. {
    14. }
    15.  
    16.  
    17. void GLWidget::paintGL()
    18. {
    19. glBegin(GL_LINE_LOOP);
    20. glVertex3d(0,0,0);
    21. glVertex3d(1,0,0);
    22. glEnd();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Here is the main file:

    Qt Code:
    1. #include <QApplication>
    2. #include "glwidget.h"
    3. #include "QDir"
    4. #include <QtGui>
    5. #include <compiler.h>
    6.  
    7. int main(int argc, char *argv[]) {
    8.  
    9. QApplication *app = new QApplication(argc, argv);
    10. QWidget *central = new QWidget();
    11. GLWidget *widget = new GLWidget(central);
    12. widget->show();
    13. return app->exec();
    14. }
    To copy to clipboard, switch view to plain text mode 
    When I run this code on unix with x11, I get a segmentation fault (that is the exact error). If I comment out everything in paintGL(), however, I do not get a segfault. In order to compile this code, I am using cmake with the addition of qt4 elements. Is the segfault a problem with my code, or with the make file?

  2. #2
    Join Date
    Sep 2008
    Posts
    25
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Segfault openGL

    That is probably because you do this in constructor:
    Quote Originally Posted by qtnewb View Post
    GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
    {
    initializeGL();
    paintGL();
    }
    You should not explicitly call to initializeGL() or paintGL(); initializeGL is called automatically, and paintGL is called when widget is redrawed, to redraw your widget manually use updateGL(), but not in constructor. You can use QTimer for automatic redrawing. Please, look in documentation and Qt sample projects to see how it is done.

Similar Threads

  1. Replies: 0
    Last Post: 6th December 2009, 00:41
  2. Qt with OpenGL ES for ARM9 - All OpenGL ES tests have failed!
    By vinpa in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd December 2009, 10:10
  3. QwtPlotMarker segfault
    By viridis in forum Qwt
    Replies: 4
    Last Post: 17th September 2008, 13:22
  4. Segfault
    By Dumbledore in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 07:31
  5. segfault
    By conexion2000 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2006, 12:34

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
  •  
Qt is a trademark of The Qt Company.