Important: Please read the Qt Code of Conduct -

[SOLVED] How to access to from Qt5 application?

  • Hello all.
    I need to create AlertDialog from Qt5 mobile application for Android with JNI.
    Some sources:

    @jclass cls = m_env_c->FindClass("android/app/AlertDialog$Builder");
    jmethodID mid = m_env_c->GetMethodID(cls, "<init>", "(Landroid/content/Context;)V");@

    To construct object i need have "android.content.Context".
    Where can i get it?

    Google says i need "" object.

    How can i get access to it from Qt5 mobile application?

    Thank you.

  • I'm not sure what you mean under “”. But if you need access to java QtActivity from c++ code you could try something like this:
    @ QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
    jobject activity = (jobject)interface->nativeResourceForIntegration("QtActivity");@
    It works for me in Qt5.1.0

    If you use Qt5.2 you may have a look at Qt Android Extras.

  • Thank you very much helped.
    Это как раз то, что и было нужно! Уже после того, как получил объект activity можно получить context и т.п. Еще раз спасибо!

  • Hello, I tried this solution, but I got a compilation error.

    "invalid use of incomplete type QPlatformNativeInterface"

    I tried to search what to include for use the QPlatformNativeInterface, but I did not find anything.

    How can I do that ??


  • If you use Qt5.2 just try Qt Android Extras. For Qt 5.1. you need to use "QPA": (Qt Platform Abstraction).
    To use QPA you need to add
    in pro:
    @QT += core gui gui-private@

    In source code:
    @#include <qpa/qplatformnativeinterface.h>@

  • @ MontezooM

    Thank you for your suggestions. I can follow your aproach for Qt5.1, but struggle getting the Java Activity (or base class Context, which would be sufficient in my case) using Qt5.2. Kindly, provide me some hints. Thanks.

    I find in android-extras two classes: QAndroidJniEnvironment (exposing JavaVM and JNIenv) and QAndroidJniObject. It seems I should use QAndroidJniEnvironment to retrieve the Java Activity/Context, but how?

Log in to reply