Hi there,
I`m new OpenGL programmer but I have some experience from programming with WinAPI+OpenGL or plain GLUT. Now I decided to move into Qt4 + OpenGL but I have plenty of troubles during getting first steps in this topic I was looking at example source code for OpenGL programs but there are too sophisicated (I don`t want to use any sliders or rotate something yet). I tried to write as simple app as it can be using source code from here:
http://doc.trolltech.com/4.4/opengl-hellogl.html
My programm compile (wrote in Qt Creator under Windows XP) without any errors but it crash and I just see Window`s error dialog with sending report about bug (i hope you know what i mean). I don`t know how to debuge OpenGL apps, so there is my whole source code:
File: window.h
Qt Code:
  1. #ifndef WINDOW_H
  2. #define WINDOW_H
  3.  
  4. #include <QtGui/QWidget>
  5. #include <QHBoxLayout>
  6. #include "ui_window.h"
  7. #include "glwidget.h"
  8.  
  9.  
  10. class Window : public QWidget
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. Window(QWidget *parent = 0, Qt::WFlags flags = 0);
  16. ~Window();
  17.  
  18. private:
  19. Ui::WindowClass ui;
  20. GLWidget* glWidget;
  21. };
  22.  
  23. #endif // WINDOW_H
To copy to clipboard, switch view to plain text mode 
File: window.cpp
Qt Code:
  1. #include "window.h"
  2.  
  3. Window::Window(QWidget *parent, Qt::WFlags flags)
  4. : QWidget(parent, flags)
  5. {
  6. ui.setupUi(this);
  7. QHBoxLayout *mainLayout = new QHBoxLayout();
  8. mainLayout->addWidget(glWidget);
  9. setLayout(mainLayout);
  10.  
  11. setWindowTitle(tr("Hello OpenGL"));
  12. }
  13.  
  14. Window::~Window()
  15. {
  16.  
  17. }
To copy to clipboard, switch view to plain text mode 
and most important files, I guess...
File: glwidget.h
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. public:
  10. GLWidget(QWidget *parent = 0);
  11. ~GLWidget();
  12.  
  13.  
  14. protected:
  15. void initializeGL();
  16. void paintGL();
  17. void resizeGL(int width, int height);
  18. };
  19. #endif // GLWIDGET_H
To copy to clipboard, switch view to plain text mode 
File: glwidget.cpp
Qt Code:
  1. #include "glwidget.h"
  2.  
  3. GLWidget::GLWidget(QWidget* parent): QGLWidget(parent)
  4. {
  5. }
  6.  
  7. GLWidget::~GLWidget()
  8. {
  9. }
  10.  
  11. void GLWidget::initializeGL()
  12. {
  13. qglClearColor(QColor(255, 0, 0, 127));
  14. glEnable(GL_DEPTH_TEST);
  15. }
  16.  
  17. void GLWidget::resizeGL(int width, int height)
  18. {
  19. int side = qMin(width, height);
  20. glViewport((width - side) / 2, (height - side)/2, side, side);
  21. glMatrixMode(GL_PROJECTION);
  22.  
  23. glLoadIdentity();
  24. glMatrixMode(GL_MODELVIEW);
  25. }
  26.  
  27. void GLWidget::paintGL()
  28. {
  29. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  30. glLoadIdentity();
  31. glBegin(GL_POLYGON);
  32. //glColor3f(1.0f, 0.4f, 0.5f);
  33. glVertex3f(-1.0f , 4.0f, 0.0f);
  34. glVertex3f(2.0f, -1.0f, 0.0f);
  35. glVertex3f(4.0f, -4.0f, -1.0f);
  36. //glColor3f(0.4f, 0.4f, 0.4f);
  37. glVertex3f(1.3f, -2.3f, -2.0f);
  38. glVertex3f(0.0f, 4.0f, -2.0f);
  39. glEnd();
  40. }
To copy to clipboard, switch view to plain text mode 
Main.cpp is of course very simple:
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "window.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication app(argc, argv);
  7. Window *window = new Window();
  8. window->show();
  9. return app.exec();
  10. }
To copy to clipboard, switch view to plain text mode 
Thank you for attention, I`m waiting for any help