Why is it impossible to use Opengl in Qt 5?

Asked

Viewed 235 times

0

Probably, Opengl is the only thing I can’t use in Qt, maya and 3ds and other Autodesk programs use opengl in Qt, but no tutorial or example that works.

I already created a class for the widget based on Qopenglwidget (Since Qglwidget is obsolete), then in the Ui editor I add a widget and promote the class I created.

Result, when I compile a white screen with no menus or anything with the frozen screen, then the application crasha.

Several tutorials do this way and it works, but with me always gives the same result, the application crasha.

https://www.youtube.com/watch?v=A-PRoXR_62Q https://www.youtube.com/watch?v=1nzHSkY4K18

They all work in video, except in practice.

glpanel code. h

#include <QtOpenGL>

class GLPanel : public QOpenGLWidget, protected QOpenGLFunctions{

    Q_OBJECT

public:

    explicit GLPanel(QWidget *parent = 0);

protected:

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

};

glpanel code.cpp

#include "glpanel.h"

GLPanel::GLPanel(QWidget *parent) :
    QOpenGLWidget(parent)
{

}

void GLPanel::initializeGL()
{
    initializeOpenGLFunctions();
}

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

}

void GLPanel::paintGL()
{

}

ui code

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>400</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Ives 3D</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0">
     <widget class="GLPanel" name="Viewport" native="true"/>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>400</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="action_Exit"/>
   </widget>
   <addaction name="menuFile"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
  <widget class="QToolBar" name="toolBar">
   <property name="windowTitle">
    <string>toolBar</string>
   </property>
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <action name="action_Exit">
   <property name="text">
    <string>&amp;Exit</string>
   </property>
  </action>
 </widget>
 <customwidgets>
  <customwidget>
   <class>GLPanel</class>
   <extends>QWidget</extends>
   <header>glpanel.h</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

Someone can give me a light ?!!

  • may be video driver problem, have you tested any opengl without using the QT library? In general AMD GPU are quite problematic on linux.

  • the most recent official example I believe is this one: http://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html

  • I do not use linux, use windows, When I create a uniquely Opengl application using Glew or SDL usually everything works, but if I try to use in Qt does not work, the proper widget of Qt crashes the application and promoting a widget too

  • try the example of this link I gave you, it is very different from what you published, maybe it works.

  • The problem is that I will use as widget, I am developing a simple modeling program so I need toolbars, layouts, etc

1 answer

0

Regarding the comment of the paulocanedo version of openGL that he posted is using shaders, this version is the latest. The advantages are the rendering speed and quality. The downside is the complexity and the need for a compatible graphics card.

Your project ran right here on Ubuntu. I made some modifications to your project and added the glut library to have an example on the screen. Link this in the description also (https://www.4shared.com/s/fS3cXWpknei). As for your error it may be the lack of an installed video drive or something related to the lack of opengl library. If your project continues to fail, try taking the initializeOpenGLFunctions(). Here I used QT 5.5.1 to compile.

  • Well, the drive I know is not the problem, Vidia even launched this month with the correction of Pectre and Meltdown, not to mention that Maya 2018 here ta normal and it is done with Qt, which brings me to some problem in Qt library, as you said you are using the 5.1, in 5.9 and 5.10 (which I’m using), so I think it’s a bug in the latest versions (although I can now use the Vulkan api in Qt)

  • You used glut and it worked for you, I’m trying to use Glew because it is free and has support for Opengl 4.6 (including some common opengl functions are having problems like "non-existent") only that all opengl functions start to give link error even with library and headers

  • Did you include the libraries in . pro and in . h and . cpp? No point just include them in the files and not inform in . pro which libs you are using on the outside.

  • I managed to solve as follows, the problem is that it is not possible to use Opengl directly in Qt, it uses Angle and ends up transforming the opengl code into directx (I do not know why to do this), I compiled a version of Qt straight from the source without Angle and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.