Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QWindow + QOpenGLContext vs QMainWindow + QGLWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QWindow + QOpenGLContext vs QMainWindow + QGLWidget

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 11.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on 28 Jul 2013, 10:44 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 28 Jul 2013, 11:42 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glararan
        wrote on 28 Jul 2013, 11:45 last edited by
        #3

        Ok Thanks for info!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          glararan
          wrote on 28 Jul 2013, 14:48 last edited by
          #4

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

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 28 Jul 2013, 15:42 last edited by
            #5

            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();
            }
            @

            1 Reply Last reply
            0
            • G Offline
              G Offline
              glararan
              wrote on 28 Jul 2013, 15:47 last edited by
              #6

              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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 28 Jul 2013, 16:19 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  glararan
                  wrote on 28 Jul 2013, 16:32 last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on 28 Jul 2013, 16:47 last edited by
                    #9

                    Yes, you need it.
                    Create QMainWindow, add QGLWidget and use QOpenGL* functions.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      glararan
                      wrote on 28 Jul 2013, 18:53 last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        ecitjiaojiao
                        wrote on 28 Mar 2014, 13:18 last edited by
                        #11

                        very usefull for me .You are a kind man, thanks

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved