PDA

View Full Version : qt with glut on windows 10



gtx
23rd August 2019, 20:12
Hey guys im trying to get glut working with opengl but getting this error

The program has unexpectedly finished

Im using windows 10 qt 5 and freeglut for mvc3.0 and visual c++
i attached a screenshot of the error

I was following this tutorial
https://www.youtube.com/watch?v=A-PRoXR_62Q
But then I gotta add glut and its not been working

This is my .pro file, if needed im also open to switching to mingw

QT += core gui opengl
LIBS += opengl32.lib -glu32
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qtopengl2
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
glwidget.cpp \
main.cpp \
mainwindow.cpp

HEADERS += \
glwidget.h \
mainwindow.h

FORMS += \
mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target


win32:CONFIG(release, debug|release): LIBS += -LD:/ufilesD/freeglutMSVC/freeglut/lib/x64/ -lfreeglut
else:win32:CONFIG(debug, debug|release): LIBS += -LD:/ufilesD/freeglutMSVC/freeglut/lib/x64/ -lfreeglut

INCLUDEPATH += D:/ufilesD/freeglutMSVC/freeglut/include
DEPENDPATH += D:/ufilesD/freeglutMSVC/freeglut/include
LIBS += -LGLU

d_stranz
23rd August 2019, 23:30
The program has unexpectedly finished

So what does the debugger's call stack output tell you about where the error has occurred and what might have caused it? Have you set a debugger breakpoint at the very first line in your program and stepped through it to see where the error occurs?

If you are going to post code or error listings, post the code and not a screenshot of the code.

gtx
24th August 2019, 02:17
Ok i'm posting other files

glwidget.h


#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>

class GLWidget : public QGLWidget
{
public:
GLWidget();

void initializeGL();
void paintGL();
void resizeGL(int w,int h);

explicit GLWidget(QWidget *parent = 0);
};

#endif // GLWIDGET_H
MainWindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

glwidget.cpp

#include "glwidget.h"
#include <GL/glut.h>

GLWidget::GLWidget(QWidget *parent):QGLWidget(parent)
{

}

GLWidget::GLWidget()
{

}

void GLWidget::initializeGL()
{
glClearColor(0,1,0,1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
}

void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,5,0,0,0,0,1,0);
glColor3f(1,0,0);
glutSolidSphere(1,20,20);
}

void GLWidget::resizeGL(int w, int h)
{

}


mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

gtx
24th August 2019, 05:55
Main.cpp


#include "mainwindow.h"
#include <QApplication>
#include <GL/glut.h>

int main(int argc, char *argv[])
{
glutInit(&argc,argv);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

also when i place the line debugger on the gluinit
it seems it something like a segmentation fault my guess cause glut isnt configured correctly, it runs for 2-3 secs then it crashes
13244

anda_skoa
24th August 2019, 08:21
Don't really have an idea on the crash, but you should not be using QGLWidget if you are on Qt5.

Use QOpenGLWidget instead.

Cheers,
_

gtx
24th August 2019, 17:25
Yea i've heard of this however the only youtube video tutorial i've found the seemed complete and i could understand was using qglwidget. I don't think qglwidget is the problem because it was working before i added the glut.

d_stranz
25th August 2019, 17:33
Where is your GLWidget being constructed? Did you add it in Qt Designer (and so it is being constructed via setupUi())?

You probably need to at least set the viewport size in the resizeGL() method:



void GLWidget::resizeGL( int w, int h )
{
glViewport( 0, 0, (GLint)w, (GLint)h );
}


You could simply your test case further by eliminating the MainWindow:



#include "glwidget.h"
#include <QApplication>
#include <GL/glut.h>

int main(int argc, char *argv[])
{
glutInit(&argc,argv);
QApplication a(argc, argv);
GLWidget w;
w.show();
return a.exec();
}


This makes the GLWidget your top-level application widget and eliminates MainWindow as the cause of any errors.

gtx
25th August 2019, 22:36
Ok i am trying that debuggin technique and I get "call to constructor of 'GLWidget is ambigous call to overloaded function could be GL::GLWidget(QWidget*)' or GL::GLWidget(void) while trying to match argument list '0' i also include the glwidgets designer view


1324813249

d_stranz
26th August 2019, 04:55
You probably need to change the signature for the GLWidget constructor to add a default value for the "parent" argument:



// glwidget.h

class GLWidget : public QGLWidget
{
Q_OBJECT

public:
GLWidget( QWidget * parent = 0 ); // default value for parent

//...
}

gtx
26th August 2019, 05:07
it did have that in glwidget.h with the word explicit at the beginning but no Q_OBJECT, i tried adding Q_OBJECT but then i get build time errors so i removed it again

anda_skoa
26th August 2019, 09:08
Yea i've heard of this however the only youtube video tutorial i've found the seemed complete and i could understand was using qglwidget. I don't think qglwidget is the problem because it was working before i added the glut.

I also don't think it is the cause of the problem but why use obsolete technology when the replacement is virtually identical in API?


it did have that in glwidget.h with the word explicit at the beginning but no Q_OBJECT, i tried adding Q_OBJECT but then i get build time errors so i removed it again

It should't matter unless you define your own slots, signals or properties.

However, if you get build errors when adding the Q_OBJECT marker the usual fix is to re-run qmake.

Cheers,
_

gtx
26th August 2019, 17:14
ok ive reran qmake and the q_object build errors went away but the program is still crashing after a few secs in runtime urgh.

d_stranz
27th August 2019, 18:30
the program is still crashing after a few secs in runtime

Then you really need to learn how to use the debugger and run your program in debug mode. When the program crashes, you look at the call stack and that will tell you the complete sequence of calls made by your program from the beginning up to the point where the crash occurs.

Just keep in mind that -where- the crash occurs might not be the actual cause that leads to the crash. For example, a memory error earlier in the program may not actually cause a problem until the code that tries to use the corrupted memory gets executed. You need to look at not only where the crash happens, but what the program is trying to do when it crashes.

Once you have established where the crash happens, if you don't understand why then report back and maybe someone here can provide some help. Just don't post screen shots of the call stack, copy and paste the text instead.

gtx
28th August 2019, 05:31
I have added that line to glwidget.h but i'm still getting call to constructor GLWidget w; is ambigous

main.cpp


GLWidget w;
w.show();
on the GLWidget w; line

d_stranz
28th August 2019, 16:43
Your GLWidget class shows two constructors in its header:



GLWidget();

// and

explicit GLWidget( QWidget * parent = 0 );


These two are indistinguishable to the compiler when used as you are doing ("GLWidget w;"). Get rid of the first constructor (GLWidget()) and the warning will go away.