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. Share QML OpenGL context and Java in Android
Forum Update on Monday, May 27th 2025

Share QML OpenGL context and Java in Android

Scheduled Pinned Locked Moved Mobile and Embedded
openglqmlandroidjava
2 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    Andy Bell
    wrote on 10 Sept 2015, 12:00 last edited by Andy Bell 9 Oct 2015, 12:02
    #1

    I have a Java library which I am using to render OpenGL. In order to use this library I need to pass it a EGLContext object. I am communicating from my QML app via QAndroidJniObject and would like to create a EGLContext object from JNI and pass it to my Java library. I have tried a number of things but I can't see a way of getting a native handle for the current OpenGL context. I have this code but nativeHandle() always returns an invlaid QVariant. Is this the right way to go or is there an easier way to do this?

    QQuickWindow * window;  // This is my app window from QQuick
    QOpenGLContext * context = window->openglContext();
                if (context != nullptr)
                {
                    QVariant nativeHandle = context->nativeHandle();
                    if (!nativeHandle.isNull() && nativeHandle.canConvert<QEGLNativeContext>())
                    {
                        QEGLNativeContext nativeContext = nativeHandle.value<QEGLNativeContext>();
                        EGLContext eglContext = nativeContext.context();
                        QAndroidJniObject egl("android/opengl/EGLContext", "(J)V", (jlong)*(int*)eglContext);
                        glContext = egl.object<jobject>();
                    }
                }
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      rhardih
      wrote on 13 Mar 2017, 09:58 last edited by
      #2

      For anyone else stumbling upon this issue. This is marked as fixed for release in 5.9:

      https://bugreports.qt.io/browse/QTBUG-43223

      1 Reply Last reply
      1

      • Login

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