Hi.
I've downloaded a simple application to see how I can draw using Opengl.
The project has only the main.cpp that have the following code:
#include <QtGui/QApplication>
#include <QGLWidget>
#include <QHBoxLayout>
#include <QSize>
#include <QPushButton>
{
Q_OBJECT
public:
{
}
float red, blue, green;
void initializeGL()
{
red = 0;
blue = 0;
green = 0;
}
public slots:
void resetColor()
{
red = 0;
blue = 0;
green = 0;
update();
}
void paintGL()
{
red += 0.007;
blue += 0.002;
green += 0.005;
glClearColor(red,green,blue,0);
glClear(GL_COLOR_BUFFER_BIT);
}
};
{
public:
MyGLWidget *glWidget = new MyGLWidget(this);
setLayout(layout);
layout->addWidget(glWidget);
layout->addWidget(button);
connect(button, SIGNAL(clicked()),glWidget, SLOT(resetColor()));
setWindowTitle("Hello World!");
sizeHint();
}
{
}
};
int main(int argc, char** argv){
MiaMainWindow win;
win.show();
int res = app.exec();
return res;
}
#include <QtGui/QApplication>
#include <QGLWidget>
#include <QHBoxLayout>
#include <QSize>
#include <QPushButton>
class MyGLWidget : public QGLWidget
{
Q_OBJECT
public:
MyGLWidget (QWidget* parent ) : QGLWidget(parent)
{
}
float red, blue, green;
void initializeGL()
{
red = 0;
blue = 0;
green = 0;
}
public slots:
void resetColor()
{
red = 0;
blue = 0;
green = 0;
update();
}
void paintGL()
{
red += 0.007;
blue += 0.002;
green += 0.005;
glClearColor(red,green,blue,0);
glClear(GL_COLOR_BUFFER_BIT);
}
};
class MiaMainWindow:public QWidget
{
public:
MiaMainWindow ():QWidget(NULL){
MyGLWidget *glWidget = new MyGLWidget(this);
QHBoxLayout *layout = new QHBoxLayout(this);
QPushButton *button = new QPushButton("Get to the Choppa!!!", this);
setLayout(layout);
layout->addWidget(glWidget);
layout->addWidget(button);
connect(button, SIGNAL(clicked()),glWidget, SLOT(resetColor()));
setWindowTitle("Hello World!");
sizeHint();
}
QSize sizeHint() const
{
return QSize(100,100);
}
};
int main(int argc, char** argv){
QApplication app(argc, argv);
MiaMainWindow win;
win.show();
int res = app.exec();
return res;
}
To copy to clipboard, switch view to plain text mode
and the .pro is the following one:
#-------------------------------------------------
#
# Project created by QtCreator 2011-09-14T20:01:51
#
#-------------------------------------------------
QT += core
QT += gui
QT += opengl
TARGET = tryme
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
#-------------------------------------------------
#
# Project created by QtCreator 2011-09-14T20:01:51
#
#-------------------------------------------------
QT += core
QT += gui
QT += opengl
TARGET = tryme
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
To copy to clipboard, switch view to plain text mode
But, when I compile it (using qtcreator 2.3.0 with Qt 4.7.4 and MinGW 4.4), I've the following errror:
debug/main.o: In function `MyGLWidget':
dir\tryme-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../tryme/main.cpp:12: undefined reference to `vtable for MyGLWidget'
dir\tryme-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../tryme/main.cpp:12: undefined reference to `vtable for MyGLWidget'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\tryme.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project tryme (target: Desktop)
When executing build step 'Make'
I've read something about this error but I don't know where's the error. Can anyone help me, please?
Thanks in advance for your replies.
Regards.
Bookmarks