Search code examples
javaandroidc++qtqtandroidextras

Calling AndroidJni static method with string parameter


I am trying to call a Java static function in Qt C++ class using QAndroidJniObject with a string parameter.

This is my Java class having function which i am calling

        public class StatusBar{

        public static void setStatusBarBackgroundColor(Activity activity,String colorPref) {

// My code


         }  
        }

I am calling this function from C++ as

void ECApplicationInfo::changeStatusBarColor(QString color)
{
  QAndroidJniObject::callStaticMethod<void>( 
                  "com/ezeecube/ezeesync/StatusBar",
                  "setStatusBarBackgroundColor",
                  "(Landroid/app/Activity;)V",
                   activity,color);
}

I am getting the following error

error: cannot pass objects of non-trivially-copyable type 'class QString' through '...' activity,color);

How can i get rid of this error


Solution

  • The definition of your function signature is not correct. You should also specify the second argument which has a type of Ljava/lang/String;. Also you should convert QString to jstring and the pass it as an argument :

    QAndroidJniObject::callStaticMethod<void>( 
                      "com/ezeecube/ezeesync/StatusBar",
                      "setStatusBarBackgroundColor",
                      "(Landroid/app/Activity;Ljava/lang/String;)V",
                       activity,QAndroidJniObject::fromString(color).object<jstring>());