1 Attachment(s)
qt with glut on windows 10
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
Re: qt with glut on windows 10
Quote:
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.
Re: qt with glut on windows 10
Ok i'm posting other files
glwidget.h
Code:
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
{
public:
GLWidget();
void initializeGL();
void paintGL();
void resizeGL(int w,int h);
explicit GLWidget
(QWidget *parent
= 0);
};
#endif // GLWIDGET_H
MainWindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
glwidget.cpp
Code:
#include "glwidget.h"
#include <GL/glut.h>
{
}
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
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
1 Attachment(s)
Re: qt with glut on windows 10
Main.cpp
Code:
#include "mainwindow.h"
#include <QApplication>
#include <GL/glut.h>
int main(int argc, char *argv[])
{
glutInit(&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
Attachment 13244
Re: qt with glut on windows 10
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,
_
Re: qt with glut on windows 10
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.
Re: qt with glut on windows 10
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:
Code:
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:
Code:
#include "glwidget.h"
#include <QApplication>
#include <GL/glut.h>
int main(int argc, char *argv[])
{
glutInit(&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.
2 Attachment(s)
Re: qt with glut on windows 10
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
Attachment 13248Attachment 13249
Re: qt with glut on windows 10
You probably need to change the signature for the GLWidget constructor to add a default value for the "parent" argument:
Code:
// glwidget.h
{
Q_OBJECT
public:
GLWidget
( QWidget * parent
= 0 );
// default value for parent
//...
}
Re: qt with glut on windows 10
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
Re: qt with glut on windows 10
Quote:
Originally Posted by
gtx
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?
Quote:
Originally Posted by
gtx
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,
_
Re: qt with glut on windows 10
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.
Re: qt with glut on windows 10
Quote:
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.
Re: qt with glut on windows 10
I have added that line to glwidget.h but i'm still getting call to constructor GLWidget w; is ambigous
main.cpp
Code:
GLWidget w;
w.show();
on the GLWidget w; line
Re: qt with glut on windows 10
Your GLWidget class shows two constructors in its header:
Code:
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.