PDA

View Full Version : Compilation Error and No output for OpenGL



Chintan
26th October 2020, 06:47
I am a newbie in QT and working with its openGL in the Ubuntu Platform

I have created a template as in :

13564

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


nearestneighbour.cpp



#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 !!");
}


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


experimental.cpp



#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();
}


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);
^~~~~~~~~~~~


2> No output is being shown in the openGL widget