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. error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor

error: cannot pass object of non-trivial type 'QtJniTypes::Context' through variadic constructor

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
jniandroid
3 Posts 2 Posters 874 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on 30 Jun 2024, 19:57 last edited by
    #1

    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?

    G 1 Reply Last reply 1 Jul 2024, 06:44
    0
    • D Dmitriano
      30 Jun 2024, 19:57

      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?

      G Offline
      G Offline
      gregory109
      wrote on 1 Jul 2024, 06:44 last edited by
      #2

      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?

      D 1 Reply Last reply 1 Jul 2024, 09:07
      0
      • G gregory109
        1 Jul 2024, 06:44

        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?

        D Offline
        D Offline
        Dmitriano
        wrote on 1 Jul 2024, 09:07 last edited by Dmitriano 7 Jan 2024, 09:08
        #3

        @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 with Q_DECLARE_JNI_CLASS(Context, "android/content/Context").

        1 Reply Last reply
        0

        2/3

        1 Jul 2024, 06:44

        • Login

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