Qt 6.8.0 - Replacement for QtNative.activity()
-
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?
-
-
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 }
-
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 !
-
-
@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.
-
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 }
-