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:
Code:
#ifndef GLWIDGET_H #define GLWIDGET_H #include <QGLWidget> #include <QtOpenGL> { Q_OBJECT public: void initializeGL(); void paintGL(); }; #endif
Here is the implementation file:
Code:
#include <QtGui> #include <QGLWidget> #include <QtOpenGL> #include "glwidget.h" { initializeGL(); paintGL(); } void GLWidget::initializeGL() { } void GLWidget::paintGL() { glBegin(GL_LINE_LOOP); glVertex3d(0,0,0); glVertex3d(1,0,0); glEnd(); }
Here is the main file:
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?Code:
#include <QApplication> #include "glwidget.h" #include "QDir" #include <QtGui> #include <compiler.h> int main(int argc, char *argv[]) { GLWidget *widget = new GLWidget(central); widget->show(); return app->exec(); }