Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to retrieve the QEGLNativeContext object?
Forum Update on Monday, May 27th 2025

How to retrieve the QEGLNativeContext object?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qeglnativeconteeglqquickwindowopengl
7 Posts 4 Posters 5.1k Views
  • 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.
  • Colin DefaisC Offline
    Colin DefaisC Offline
    Colin Defais
    wrote on last edited by Colin Defais
    #1

    Hello,

    I would like to use some advanced EGL/OpenGL functions like eglCreateImageKHR() in a QtQuick window.

    To do so I need a reference to the EGL display and the EGL context.

    Today I am able to retrieve the QOpenGLContext of my window with a connection to its openglContextCreated signal.

    Then I could retrieve the associated QEGLNativeContext with myQOpenGLContext->nativeHandle().
    If I understand well the documentation, myQOpenGLContext->nativeHandle() should be a QVariant of a QEGLNativeContext object.

    But I don't understand how to convert this QVariant to a QEGLNativeContext object.

    My target is an i.mx6Q with a yocto from december 2015 and wayland-egl as backend.

    I hope someone might help,

    Regards

    Colin DefaisC 1 Reply Last reply
    0
    • Colin DefaisC Colin Defais

      Hello,

      I would like to use some advanced EGL/OpenGL functions like eglCreateImageKHR() in a QtQuick window.

      To do so I need a reference to the EGL display and the EGL context.

      Today I am able to retrieve the QOpenGLContext of my window with a connection to its openglContextCreated signal.

      Then I could retrieve the associated QEGLNativeContext with myQOpenGLContext->nativeHandle().
      If I understand well the documentation, myQOpenGLContext->nativeHandle() should be a QVariant of a QEGLNativeContext object.

      But I don't understand how to convert this QVariant to a QEGLNativeContext object.

      My target is an i.mx6Q with a yocto from december 2015 and wayland-egl as backend.

      I hope someone might help,

      Regards

      Colin DefaisC Offline
      Colin DefaisC Offline
      Colin Defais
      wrote on last edited by Colin Defais
      #2

      I have tried the following (using qvariant_cast) :
      qEglContext = qvariant_cast<QEGLNativeContext* >(context->nativeHandle());

      But at build time I get a static assertion failed error: Type is not registered.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        I haven't used it yet but from the documentation, that function returns a value type not a pointer. Try with qvariant_cast<QEGLNativeContext>(context->nativeHandle())

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Colin DefaisC 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          I haven't used it yet but from the documentation, that function returns a value type not a pointer. Try with qvariant_cast<QEGLNativeContext>(context->nativeHandle())

          Colin DefaisC Offline
          Colin DefaisC Offline
          Colin Defais
          wrote on last edited by
          #4

          Thanks @SGaist!

          I have tried with the value type and the static cast seems to work (no error at build time).

          But now, I would like to use the eglCreateImageKHR() function.
          Following is what I have trieed so far:

          1 - I prepare my image attributes array (I might need to check those values later to ensure compatibility):

          EGLint eglImageAttributes[] = {EGL_WIDTH, m_window->width(), EGL_HEIGHT, m_window->height(), EGL_MATCH_FORMAT_KHR, EGL_FORMAT_RGBA_8888_KHR, EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
          

          2 - Then I retrieve the QEGLNativeContext as you suggested:

          QEGLNativeContext qEglContext = qvariant_cast<QEGLNativeContext>(context->nativeHandle());
          

          3 - And finaly I make the call to eglCreateImageKHR():

          EGLImageKHR eglImageHandle = eglCreateImageKHR(qEglContext.display(), qEglContext.context(), EGL_GL_RENDERBUFFER_KHR, (EGLClientBuffer)m_window->OpenGLSurface, eglImageAttributes);
          

          4 - But it fails:

          eglCreateImageKHR returns EGL_NO_IMAGE_KHR and eglGetError() returns EGL_BAD_DISPLAY.

          According to the eglCreateImageKHR() documentation, eglCreateImageKHR() generates an EGL_BAD_DISPLAY error when the handle (qEglContext.display()) is not valid:

          If <dpy> is not the handle of a valid EGLDisplay object, the error EGL_BAD_DISPLAY is generated
          

          So, where am I wrong?
          My code is fired by the the onOpenglContextCreated() signal. Also, I am pretty sure I am using an EGL backend since at run-time the logs say "Using Wayland-EGL".
          Why qEglContext.display() seems to be invalid?

          Any suggestions?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            For that one, I'd recommend checking with the Wayland folks. I haven't used it yet so I can't be of help here, sorry.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vpanchal
              wrote on last edited by
              #6

              Hi Colin,

              I'm working on something similar. Was this issue ever resolved? If so, do you mind sharing?

              Thanks,
              Vishal

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hehehehehe
                wrote on last edited by
                #7

                Hi ,

                I'm working on something similar. Was this issue ever resolved? If so, do you mind sharing?
                I found the qEglContext.display() return NULL.

                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