I am trying to run basic OpenGL examples using QT Creator to give color to a window. However, I get a compilation error when invoking the OpenGL instruction: glClearColor (1.0,1.0,0.0,1,0); The * .pro file is as follows:
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test2
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp
HEADERS += mainwindow.h \
glwidget.h
FORMS += mainwindow.ui
Next is glwidget.h:
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent = 0);
void initializeGL();
};
#endif
glwidget.cpp is as follows:
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL(){
glClearColor(1.0,1.0,0.0,1.0);
}
Main.cpp file:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
I checked that in * .pro I included opengl: QT + = core gui opengl In addition, I deleted the folder "YourProjectName-build-desktop" created by QT Creator and built it again without success.
Error: C: \ test2 \ glwidget.cpp: 9: error: undefined reference to `_imp__glClearColor @ 16 'where line 9 is glClearColor (1,0,1,0,0,0,1,0);
What extra step am I missing?
Thank you in advance for your help.
© 2016 Microsoft cookie English (United States)