error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor
-
The following code stopped compiling for Android with QT 6.7.2:
m_javaObject = QJniObject("org/qtproject/qt/android/purchasing/InAppPurchase", "(Landroid/content/Context;J)V", QNativeInterface::QAndroidApplication::context(), this);
The error is:
error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor; call will abort at runtime [-Wnon-pod-varargs] QNativeInterface::QAndroidApplication::context(),
As far as I can guess, Context type is not trivial anymore and can't be passed as an argument of a function with three dots in its signature like
QJniObject(const char *className, const char *signature, ...);
What is the workaround?
-
Hello, @Dmitriano
The issue you’re encountering is related to passing a non-trivial type (specifically, QtJniTypes::Context) through a variadic constructor. In Qt 6.7.2, the QJniObject constructor expects a variadic argument list, but passing non-trivial types directly can cause problems.
To work around this, you can use the following approach:
Create a Local Variable:
Instead of passing QNativeInterface::QAndroidApplication::context() directly, create a local variable of type QtJniTypes::Context.
Then pass that local variable to the QJniObject constructor.
Here’s an example of how you can modify your code:// Create a local variable of type QtJniTypes::Context
QtJniTypes::Context androidContext = QNativeInterface::QAndroidApplication::context();// Pass the local variable to the QJniObject constructor
m_javaObject = QJniObject("org/qtproject/qt/android/purchasing/InAppPurchase",
"(Landroid/content/Context;J)V",
androidContext,
this);By using a local variable, you avoid passing non-trivial types directly through the variadic constructor, and it should compile without issues.
Remember to adjust the variable names and context as needed for your specific use case.
I hope this info is helpful to you.
Best Regard,
Gregory Chavez@Dmitriano Official Site said in error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor:
The following code stopped compiling for Android with QT 6.7.2:
m_javaObject = QJniObject("org/qtproject/qt/android/purchasing/InAppPurchase", "(Landroid/content/Context;J)V", QNativeInterface::QAndroidApplication::context(), this);
The error is:
error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor; call will abort at runtime [-Wnon-pod-varargs] QNativeInterface::QAndroidApplication::context(),
As far as I can guess, Context type is not trivial anymore and can't be passed as an argument of a function with three dots in its signature like
QJniObject(const char *className, const char *signature, ...);
What is the workaround?
-
@gregory109 I tried:
QtJniTypes::Context context = QNativeInterface::QAndroidApplication::context(); m_javaObject = QJniObject("org/qtproject/qt/android/purchasing/InAppPurchase", "(Landroid/content/Context;J)V", context, this);
but it did not help. Looks like
QtJniTypes::Context
is not a trivial type defined withQ_DECLARE_JNI_CLASS(Context, "android/content/Context")
.