Results 1 to 15 of 15

Thread: qt with glut on windows 10

  1. #1
    Join Date
    Aug 2019
    Posts
    8

    Default 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
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qt with glut on windows 10

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Aug 2019
    Posts
    8

    Default Re: qt with glut on windows 10

    Ok i'm posting other files

    glwidget.h

    Qt Code:
    1. #ifndef GLWIDGET_H
    2. #define GLWIDGET_H
    3.  
    4. #include <QGLWidget>
    5.  
    6. class GLWidget : public QGLWidget
    7. {
    8. public:
    9. GLWidget();
    10.  
    11. void initializeGL();
    12. void paintGL();
    13. void resizeGL(int w,int h);
    14.  
    15. explicit GLWidget(QWidget *parent = 0);
    16. };
    17.  
    18. #endif // GLWIDGET_H
    To copy to clipboard, switch view to plain text mode 
    MainWindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = nullptr);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. };
    21.  
    22. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    glwidget.cpp
    Qt Code:
    1. #include "glwidget.h"
    2. #include <GL/glut.h>
    3.  
    4. GLWidget::GLWidget(QWidget *parent):QGLWidget(parent)
    5. {
    6.  
    7. }
    8.  
    9. GLWidget::GLWidget()
    10. {
    11.  
    12. }
    13.  
    14. void GLWidget::initializeGL()
    15. {
    16. glClearColor(0,1,0,1);
    17. glEnable(GL_DEPTH_TEST);
    18. glEnable(GL_LIGHT0);
    19. glEnable(GL_LIGHTING);
    20. glEnable(GL_COLOR_MATERIAL);
    21. }
    22.  
    23. void GLWidget::paintGL()
    24. {
    25. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    26. glMatrixMode(GL_MODELVIEW);
    27. glLoadIdentity();
    28. gluLookAt(0,0,5,0,0,0,0,1,0);
    29. glColor3f(1,0,0);
    30. glutSolidSphere(1,20,20);
    31. }
    32.  
    33. void GLWidget::resizeGL(int w, int h)
    34. {
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2019
    Posts
    8

    Default Re: qt with glut on windows 10

    Main.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <GL/glut.h>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. glutInit(&argc,argv);
    8. QApplication a(argc, argv);
    9. MainWindow w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    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
    segfault.jpg

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  6. #6
    Join Date
    Aug 2019
    Posts
    8

    Default 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.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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:

    Qt Code:
    1. void GLWidget::resizeGL( int w, int h )
    2. {
    3. glViewport( 0, 0, (GLint)w, (GLint)h );
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. #include "glwidget.h"
    2. #include <QApplication>
    3. #include <GL/glut.h>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. glutInit(&argc,argv);
    8. QApplication a(argc, argv);
    9. GLWidget w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    This makes the GLWidget your top-level application widget and eliminates MainWindow as the cause of any errors.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Aug 2019
    Posts
    8

    Default 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


    glwidgetanonymous.jpgqtdesign.jpg

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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:

    Qt Code:
    1. // glwidget.h
    2.  
    3. class GLWidget : public QGLWidget
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. GLWidget( QWidget * parent = 0 ); // default value for parent
    9.  
    10. //...
    11. }
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    Aug 2019
    Posts
    8

    Default 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

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qt with glut on windows 10

    Quote Originally Posted by gtx View Post
    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 View Post
    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,
    _

  12. #12
    Join Date
    Aug 2019
    Posts
    8

    Default 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.

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qt with glut on windows 10

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  14. #14
    Join Date
    Aug 2019
    Posts
    8

    Default 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

    Qt Code:
    1. GLWidget w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 
    on the GLWidget w; line

  15. #15
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,136
    Thanks
    235
    Thanked 660 Times in 650 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qt with glut on windows 10

    Your GLWidget class shows two constructors in its header:

    Qt Code:
    1. GLWidget();
    2.  
    3. // and
    4.  
    5. explicit GLWidget( QWidget * parent = 0 );
    To copy to clipboard, switch view to plain text mode 

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Linking glut to Qt
    By Mashkur in forum Qt Tools
    Replies: 1
    Last Post: 14th October 2012, 18:18
  2. How to link glut.h?
    By connect_qt in forum Newbie
    Replies: 3
    Last Post: 15th November 2011, 22:14
  3. Qi with glut
    By hudi in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2010, 11:41
  4. using GLUT along with qtcreator/mingw in windows
    By stephanepoirier in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2009, 05:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.