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