[SOLVED] QWindow + QOpenGLContext vs QMainWindow + QGLWidget
-
wrote on 28 Jul 2013, 10:44 last edited by
Hello,
Im starting this discussion because i read on http://www.kdab.com/category/blogs/ QWindow with QOpenGLContext will be better in Qt 5+ then QMainWindow + QGLWidget.
But here come my problem. When I want to call QMenuBar, app crash because actually I don't created QApplication
QCoreApplication <- QGuiApplication(my) <- QApplication (not my, here is QWidget)
How I can create Menu and other things, when I dont have QWidget? Is there any possible way?
-
QWindow is the bare native window that you can draw on using QOpenGLContext or QBackingStore. It has no direct support for placing widgets in it and it is best when you want to draw everything on your own inside your opengl code.
If you'd like to use Qt for your ui there are basically two ways: widgets or qml, in other words you ditch the QWindow and go for QWidget/QMainWindow or QQuickView.
-
wrote on 28 Jul 2013, 11:45 last edited by
Ok Thanks for info!
-
wrote on 28 Jul 2013, 14:48 last edited by
Sorry for double, I dont want to start new topic, thread is less diffrent.
Can I use QOpenGLContext with QMainWindow? Is it possible or isnt?
I currently have one problem, in one example they're using new function from class QOpenGLShaderProgram.. -
With QMainWindow you can use QGLWidget, which uses QGLContext (access through "context":http://qt-project.org/doc/qt-5.1/qtopengl/qglwidget.html#context member), from which you can get a handle to the QOpenGLContext via "contextHandle":http://qt-project.org/doc/qt-5.1/qtopengl/qglcontext.html#contextHandle
For example:
@
void MyGlWidget::initializeGL()
{
QSurfaceFormat sf = context()->contextHandle()->format();
qDebug() << sf.majorVersion() << sf.minorVersion();
}
@ -
wrote on 28 Jul 2013, 15:47 last edited by
So its possible to get QOpenGLShaderProgram or not? Also QGL dont have QOpenGLVertexArrayObject which I want to use.
EDIT:
QOpenGLShader - ShaderTypes:QOpenGLShader::Vertex
QOpenGLShader::Fragment
QOpenGLShader::Geometry
QOpenGLShader::TessellationControl
QOpenGLShader::TessellationEvaluation
QOpenGLShader::Compute
QGLShader - Shader Types:
QGLShader::Vertex
QGLShader::Fragment
QGLShader::Geometry
I want to use for Shading: TessellationControl
-
Yes, you can(and should) use it, and by the way - it doesn't matter if you use QOpenGL*, QGL* or plain gl* via the QOpenGLFunctions or via another library.
They all do the same and simply require active OpenGL context.But just to be clear - most of the QGL* stuff is being deprecated in Qt5 by the QOpenGL* counterparts, so stick to those and don't mix them (QGLWidget and QGLContext being an exception, as they are a bridge between the new shiny QSurface and the old but gold QWidgets.
-
wrote on 28 Jul 2013, 16:32 last edited by
Ok, I just simply want use QOpenGL* with GUI, and there was the first problem, QWindow doesn't have and I don't want to use QML, I want to stay in pure Qt C++ (I know designers are in XML or something like that).
So I will create MainWindow and I can start using QOpenGL* or still need QGLWidget?
-
Yes, you need it.
Create QMainWindow, add QGLWidget and use QOpenGL* functions. -
wrote on 28 Jul 2013, 18:53 last edited by
Ok thanks, before you post it, I started this way. Now I'm finally undestand why you post code with QSurfaceFormat.
Thank you very much!
For people with same problem: QOpenGLContext from QGLWidget you get inside QGLWidget class with call:
@m_context = this->context()->contextHandle();@EDIT: Im succesfully moved QWindow + QOpenGLContext to QMainWindow + QGLWidget + QOpenGLContext
-
wrote on 28 Mar 2014, 13:18 last edited by
very usefull for me .You are a kind man, thanks