使用Qt / C + +通过JNI调用Java代码

http://www.4byte.cn/question/260046/using-qt-c-to-call-java-code-through-jni-findclass-does-not-find-class.html



http://www.4byte.cn/question/106668/calling-java-method-from-c-in-qt.html



https://github.com/search?utf8=%E2%9C%93&q=qt+jni



http://forum.qt.io/topic/36143/how-to-call-non-static-java-method-in-qtactivity-from-c-qt


http://forum.qt.io/topic/49818/using-getrssi-from-qandroidjniobject-qt-widget


http://forum.qt.io/topic/33312/how-to-call-vibrator-in-qt-for-android


http://forum.qt.io/topic/33491/need-android-vibration-example-based-on-qandroidjni/2


http://forum.qt.io/topic/46885/qt-c-based-library-on-android-using-jni-missing-initialization-of-qt-libs


http://forum.qt.io/topic/27183/pdf-reader-for-embedded/2


https://www.calligra.org/blogs/sharing-with-qt-on-android/


http://www.qtdeveloperdays.com/sites/default/files/BogdanVatra_Extending_Qt_Android_Apps_with_JNI.pdf



https://github.com/search?l=C%2B%2B&q=qt+java&ref=searchresults&type=Repositories&utf8=%E2%9C%93



http://stackoverflow.com/questions/18052887/native-using-java-functions-3rd-party-libraries-in-qt-for-android



http://www.169it.com/tech-mobile-dev/article-5989289679902141045.html


http://qt-project.org/wiki/KorhalResearch


http://blog.csdn.net/xj626852095/article/details/41147441


https://qt.gitorious.org/qt/grym-android-lighthouse/source/b62133d37e1b4d60fc5599ab7766b555abc9d95f:src/plugins/platforms/android/grym/java/src/org/qt/core/QtActivityBase.java




http://code.freedomho.com/75919.html




https://github.com/benlau/qtandroidexamplecode/tree/master/qtandroidrunner



http://events.linuxfoundation.org/sites/events/files/slides/android-without-java.pdf



https://community.kde.org/Necessitas/JNI



https://github.com/tugrulyatagan/harita



https://github.com/FenixVoltres/QtAndroidNativeLib



https://github.com/FenixVoltres/QtAndroidSplash

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java使用JNIJava Native Interface)调用Qt方法,您需要进行以下步骤: 1. 编写Qt代码:首先,您需要编写您想要在Qt调用的功能代码。确保将该功能封装在一个类中,并在该类的头文件中声明该函数。 2. 生成动态链接库:使用Qt提供的工具(例如qmake或CMake),将您的Qt代码编译为动态链接库(DLL或SO文件)。确保导出您想要从Java调用的函数。 3. 生成JNI头文件:使用Java提供的工具(例如javah),生成JNI头文件。该头文件将包含用于在Java调用C/C++代码的函数声明。 4. 实现JNI方法:在您的C/C++代码中,实现JNI方法,以便在Java调用Qt方法。这些方法将是JNI头文件中声明的函数。 5. 将动态链接库与Java绑定:在Java代码中,使用System.loadLibrary()方法加载生成的动态链接库。然后,使用JNI提供的功能(例如JNIEnv和jobject)在Java调用C/C++方法。 以下是一个简单的示例: Qt代码(myclass.h): ```cpp #ifndef MYCLASS_H #define MYCLASS_H #include <QObject> class MyClass : public QObject { Q_OBJECT public: explicit MyClass(QObject *parent = nullptr); public slots: void myFunction(); }; #endif // MYCLASS_H ``` Qt代码(myclass.cpp): ```cpp #include "myclass.h" #include <QDebug> MyClass::MyClass(QObject *parent) : QObject(parent) { } void MyClass::myFunction() { qDebug() << "Qt function called from JNI"; } ``` 生成动态链接库:使用Qt提供的工具(例如qmake或CMake)将Qt代码编译为动态链接库。 生成JNI头文件:在命令行中,导航到包含Java类文件的目录,并运行以下命令: ``` javah -jni com.example.MyClass ``` 这将在该目录中生成一个名为"com_example_MyClass.h"的JNI头文件。 实现JNI方法:在C/C++代码中,实现JNI方法。例如,您可以创建一个名为"com_example_MyClass.cpp"的文件,并编写以下内容: ```cpp #include "com_example_MyClass.h" #include "myclass.h" JNIEXPORT void JNICALL Java_com_example_MyClass_myFunction(JNIEnv *, jobject) { MyClass myClass; myClass.myFunction(); } ``` 将动态链接库与Java绑定:在Java代码中,使用System.loadLibrary()方法加载生成的动态链接库,并调用JNI方法。例如: ```java package com.example; public class MyClass { static { System.loadLibrary("mylibrary"); } private native void myFunction(); public static void main(String[] args) { MyClass myClass = new MyClass(); myClass.myFunction(); } } ``` 请注意,这只是一个简单的示例,以帮助您入门。实际上,JNI使用可能会更加复杂,并涉及到处理数据类型转换、异常处理等方面的内容。确保阅读JNI文档以获取更多详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值