软件版本号:
Qt 4.8.5


依照网上的例程(http://www.qiliang.net/old/nehe_qt/lesson01.html),跑了一下基于Qt Creator的OpenGL。因为上述例程的Qt版本号较老(例程是02年的,汗。),在新的Qt环境下产生诸多问题,好在一一得到了解决,现说明例如以下:



1、须要在project文件.pro中加入对OpenGL的支持:



QT += opengl(记得清理项目后再编译!)


否则会出现一大堆类似error: undefined reference to `glShadeModel@4'、error: undefined reference to `glClearColor@16'的问题。


Qt编译OpenGL程序遇到的问题_#include



2、对于设置窗体Title的函数setCaption:


[error: 'setCaption' was not declared in this scope]


在新版本号中已经废弃。改而用setWindowTitle()函数取代:



setCaption("Qt Open-GL");——>setWindowTitle("Qt Open-GL");



3、对于glu开头的函数,如gluPerspective():


[error: 'gluPerspective' was not declared in this scope]


须要包括头文件

#include <GL/glu.h>



4、用到QKeyEvent,须要包括其头文件


[error: invalid use of incomplete type 'struct QKeyEvent']

#include <QKeyEvent>