java - Qt调用具有多个参数的java方法
问题描述
我检查了 android 的 Qt Notifier 示例:https ://doc.qt.io/qt-5/qtandroidextras-notification-example.html 在此示例中,使用 2 个参数调用 Java 方法,如下所示:
void NotificationClient::updateAndroidNotification()
{
QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);
QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
"notify",
"(Ljava/lang/String;)V",
javaNotification.object<jstring>());
}
我很难理解我应该在这里传递哪些参数来调用带有 2 个参数的函数,而不是一个。例如,该函数当前采用 1 个参数:
public static void notify(String s)
{
if (m_notificationManager == null) {
m_notificationManager =
(NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
m_builder = new Notification.Builder(m_instance);
m_builder.setSmallIcon(R.drawable.icon);
m_builder.setContentTitle("A message from Qt!");
}
m_builder.setContentText(s);
m_notificationManager.notify(1, m_builder.build());
}
我可以在方法本身()中添加另一个public static void notify(String s, String x)
,但是如何处理 cpp 部分?
解决方案
它应该是
QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
"notify",
"(Ljava/lang/String;Ljava/lang/String;)V",
javaNotification.object<jstring>(),
somethingelse.object<jstring>());
如此处所述。
推荐阅读
- mysql - Mysql加入按列分组以删除重复但仍返回行数据
- wordpress - 具有给定设计的 wp_posts 没有正确重复
- c# - 如何在 Telerik 的 RadCartesianChart 的工具提示中显示不受 CategoryPath 或 ValuePath 约束的值?
- string - 如何使用移位从 MIPS32 程序集中的 4 字节字符串中删除字符?
- scala - 如何为类型 Iterator[org.apache.spark.sql.Row] 创建编码器
- ios - 如何在发送时不显示推送消息的情况下运行该功能?
- mysql - 在这个表结构中,如何按字段值搜索文章?
- tensorflow - 从 Keras 模型的 predict() 方法返回实例 ID 和预测
- reactjs - React EdiText - 使用 Enter 键提交
- java - 通过 JNI 创建和设置数组