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. Qt 6.8.0 - Replacement for QtNative.activity()
QtWS25 Last Chance

Qt 6.8.0 - Replacement for QtNative.activity()

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 704 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.
  • NaLogoN Offline
    NaLogoN Offline
    NaLogo
    wrote on last edited by
    #1

    Hello everyone.

    I'm looking into migrating a project from Qt 6.5 to Qt 6.8

    In a Java class, I am accessing the Qt Activity using QtNative.activity() - this no longer works due to 6.8 changing the activity() from public to private.

    Is there a replacement for this? A way to access the activity without having to pass it to a method myself?

    jsulmJ 1 Reply Last reply
    0
    • P Parvathy2020 referenced this topic on
    • NaLogoN Offline
      NaLogoN Offline
      NaLogo
      wrote on last edited by NaLogo
      #5

      My workaround for the time being is as follows:

      • Construct the Java class when the related C++ class is constructed
      • Set Activity for the class
      • Call static methods like before

      Java:

      private static Activity m_activity = null;
      
      public void setActivity(Activity activity) {
          m_activity = activity;
          return;
      }
      

      also change all methods that previously called QtNative.activity() to now check for and use m_activity instead.

      C++:

      mJNIInstance = QJniObject("the/qualified/ClassPath");
      if (mJNIInstance.isValid()) {
          mJNIInstance.callMethod<void>("setActivity", "(Landroid/app/Activity;)V", QNativeInterface::QAndroidApplication::context().object());
      } else {
          // output a warning or error
      }
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        Parvathy2020
        wrote on last edited by Parvathy2020
        #2

        Hi @NaLogo , If you got solution for the above mentioned problem , can you please provide the changes you made to resolve the issue. Thanks in advance !

        1 Reply Last reply
        0
        • NaLogoN NaLogo

          Hello everyone.

          I'm looking into migrating a project from Qt 6.5 to Qt 6.8

          In a Java class, I am accessing the Qt Activity using QtNative.activity() - this no longer works due to 6.8 changing the activity() from public to private.

          Is there a replacement for this? A way to access the activity without having to pass it to a method myself?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @NaLogo Take a look at https://forum.qt.io/topic/159644/qt-6-8-emailsender-activity-is-not-public-in-qtnative-cannot-be-accessed-from-outside-package/6

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          NaLogoN 1 Reply Last reply
          0
          • jsulmJ jsulm

            @NaLogo Take a look at https://forum.qt.io/topic/159644/qt-6-8-emailsender-activity-is-not-public-in-qtnative-cannot-be-accessed-from-outside-package/6

            NaLogoN Offline
            NaLogoN Offline
            NaLogo
            wrote on last edited by
            #4

            @jsulm said in Qt 6.8.0 - Replacement for QtNative.activity():

            @NaLogo Take a look at https://forum.qt.io/topic/159644/qt-6-8-emailsender-activity-is-not-public-in-qtnative-cannot-be-accessed-from-outside-package/6

            Like the user in that thread you linked pointed out, it doesn't work like that. The reason for that being what I wrote in my original post: The scope of the method QtNative.activity() in QtNative.java was changed from public to private (by removing the scope) between Qt 6.5 and Qt 6.8

            @Parvathy2020 said in Qt 6.8.0 - Replacement for QtNative.activity():

            Hi @NaLogo , If you got solution for the above mentioned problem , can you please provide the changes you made to resolve the issue. Thanks in advance !

            I haven't tried it yet, but it probably requires an additional call that will pass the activity from the main app to the native class (storing it in a variable, of course) before calling the method you actually want. I'll post the results here when and if I get around to trying it.

            1 Reply Last reply
            0
            • NaLogoN Offline
              NaLogoN Offline
              NaLogo
              wrote on last edited by NaLogo
              #5

              My workaround for the time being is as follows:

              • Construct the Java class when the related C++ class is constructed
              • Set Activity for the class
              • Call static methods like before

              Java:

              private static Activity m_activity = null;
              
              public void setActivity(Activity activity) {
                  m_activity = activity;
                  return;
              }
              

              also change all methods that previously called QtNative.activity() to now check for and use m_activity instead.

              C++:

              mJNIInstance = QJniObject("the/qualified/ClassPath");
              if (mJNIInstance.isValid()) {
                  mJNIInstance.callMethod<void>("setActivity", "(Landroid/app/Activity;)V", QNativeInterface::QAndroidApplication::context().object());
              } else {
                  // output a warning or error
              }
              
              1 Reply Last reply
              0
              • NaLogoN NaLogo has marked this topic as solved on

              • Login

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