I am a newbie in QT and working with its openGL in the Ubuntu Platform
I have created a template as in :
worktable.jpg
My objective :
On clicking of the "Compute" Button, two things are supposed to happen :
1> A text will be printed in the in the text box 2> A line will be drawn on expOutput, which is an object of Experimental, inherited from QGLWidget.
I am creating two signal slots. The codes of the program is given as below :
nearestneighbour.h
#ifndef NEARESTNEIGHBOUR_H
#define NEARESTNEIGHBOUR_H
#include <QWidget>
#include <QGLWidget>
namespace Ui {
class NearestNeighbour;
}
class NearestNeighbour
: public QWidget{
Q_OBJECT
public:
explicit NearestNeighbour
(QWidget *parent
= 0);
~NearestNeighbour();
signals:
void clicked();
private slots:
void on_Compute_clicked();
private:
Ui::NearestNeighbour *ui;
};
#endif // NEARESTNEIGHBOUR_H
#ifndef NEARESTNEIGHBOUR_H
#define NEARESTNEIGHBOUR_H
#include <QWidget>
#include <QGLWidget>
namespace Ui {
class NearestNeighbour;
}
class NearestNeighbour : public QWidget
{
Q_OBJECT
public:
explicit NearestNeighbour(QWidget *parent = 0);
~NearestNeighbour();
signals:
void clicked();
private slots:
void on_Compute_clicked();
private:
Ui::NearestNeighbour *ui;
};
#endif // NEARESTNEIGHBOUR_H
To copy to clipboard, switch view to plain text mode
nearestneighbour.cpp
#include "nearestneighbour.h"
#include "ui_nearestneighbour.h"
NearestNeighbour
::NearestNeighbour(QWidget *parent
) : ui(new Ui::NearestNeighbour)
{
ui->setupUi(this);
QObject::connect(ui
->Compute,
SIGNAL(clicked
()), ui
->expOutput,
SLOT(draw
()));
QObject::connect(ui
->Compute,
SIGNAL(clicked
()), ui
->textEdit,
SLOT(on_Compute_clicked
()));
}
NearestNeighbour::~NearestNeighbour()
{
delete ui;
}
void NearestNeighbour::on_Compute_clicked()
{
ui->textEdit->setText("Hello World !!");
}
#include "nearestneighbour.h"
#include "ui_nearestneighbour.h"
NearestNeighbour::NearestNeighbour(QWidget *parent) :
QWidget(parent),
ui(new Ui::NearestNeighbour)
{
ui->setupUi(this);
QObject::connect(ui->Compute, SIGNAL(clicked()), ui->expOutput,SLOT(draw()));
QObject::connect(ui->Compute, SIGNAL(clicked()), ui->textEdit,SLOT(on_Compute_clicked()));
}
NearestNeighbour::~NearestNeighbour()
{
delete ui;
}
void NearestNeighbour::on_Compute_clicked()
{
ui->textEdit->setText("Hello World !!");
}
To copy to clipboard, switch view to plain text mode
experimental.h
#ifndef EXPERIMENTAL_H
#define EXPERIMENTAL_H
#include <QWidget>
#include <QGLWidget>
#include "nearestneighbour.h"
#include "ui_nearestneighbour.h"
{
Q_OBJECT
public:
explicit Experimental
(QWidget *parent
=NULL);
public slots:
void draw();
protected:
void initializeGL();
void paintGL();
};
#endif // EXPERIMENTAL_H
#ifndef EXPERIMENTAL_H
#define EXPERIMENTAL_H
#include <QWidget>
#include <QGLWidget>
#include "nearestneighbour.h"
#include "ui_nearestneighbour.h"
class Experimental : public QGLWidget
{
Q_OBJECT
public:
explicit Experimental(QWidget *parent=NULL);
public slots:
void draw();
protected:
void initializeGL();
void paintGL();
};
#endif // EXPERIMENTAL_H
To copy to clipboard, switch view to plain text mode
experimental.cpp
#include "experimental.h"
void Experimental::initializeGL(){
qglClearColor(Qt::white);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
}
void Experimental::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
qglColor(Qt::black);
glBegin(GL_LINE);
glVertex2i(0,0);
glVertex2i(200,200);
glEnd();
}
void Experimental::draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
qglColor(Qt::black);
glBegin(GL_LINE);
glVertex2i(0,0);
glVertex2i(200,200);
glEnd();
updateGL();
}
#include "experimental.h"
Experimental::Experimental(QWidget *parent): QGLWidget(QGLFormat(QGL::SampleBuffers), parent){}
void Experimental::initializeGL(){
qglClearColor(Qt::white);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
}
void Experimental::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
qglColor(Qt::black);
glBegin(GL_LINE);
glVertex2i(0,0);
glVertex2i(200,200);
glEnd();
}
void Experimental::draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
qglColor(Qt::black);
glBegin(GL_LINE);
glVertex2i(0,0);
glVertex2i(200,200);
glEnd();
updateGL();
}
To copy to clipboard, switch view to plain text mode
Problem :
1> Whenever, I compile the program, the following error creeps up :
In file included from ../NearestNeighbour/experimental.h:7:0,
from ../NearestNeighbour/experimental.cpp:1:
./ui_nearestneighbour.h:28:5: error: ‘Experimental’ does not name a type; did you mean ‘isprint_l’?
Experimental *expOutput;
^~~~~~~~~~~~
isprint_l
.
/ui_nearestneighbour.
h: In member function ‘
void Ui_NearestNeighbour
::setupUi(QWidget*)’
:./ui_nearestneighbour.h:38:9: error: ‘expOutput’ was not declared in this scope
expOutput = new Experimental(NearestNeighbour);
^~~~~~~~~
./ui_nearestneighbour.h:38:25: error: expected type-specifier before ‘Experimental’
expOutput = new Experimental(NearestNeighbour);
^~~~~~~~~~~~
In file included from ../NearestNeighbour/experimental.h:7:0,
from ../NearestNeighbour/experimental.cpp:1:
./ui_nearestneighbour.h:28:5: error: ‘Experimental’ does not name a type; did you mean ‘isprint_l’?
Experimental *expOutput;
^~~~~~~~~~~~
isprint_l
./ui_nearestneighbour.h: In member function ‘void Ui_NearestNeighbour::setupUi(QWidget*)’:
./ui_nearestneighbour.h:38:9: error: ‘expOutput’ was not declared in this scope
expOutput = new Experimental(NearestNeighbour);
^~~~~~~~~
./ui_nearestneighbour.h:38:25: error: expected type-specifier before ‘Experimental’
expOutput = new Experimental(NearestNeighbour);
^~~~~~~~~~~~
To copy to clipboard, switch view to plain text mode
2> No output is being shown in the openGL widget
Bookmarks