Qt Java function call via JNI
-
Hi,
I am currently working on a Qt desktop application (Qt 5.15) where we would like to make some function calls from a Java application(jar file). It seems that using JNI could be a nice way to do that quickly instead of building an IPC mechanism.
But after some research, I realized that the JNI is currently available only on Qt Android Extras module and we want to use JNI functions on our desktop application. Is there a different way to do that and take advantage of the QAndroidJniObject ? Any other ideas/alternatives on how to do that integration quickly between two applications? Also, I think that in Qt6 maybe it is possible to use JNI in other platforms other than Android but I am not very sure about that.
Thanks!
-
Hi,
I am currently working on a Qt desktop application (Qt 5.15) where we would like to make some function calls from a Java application(jar file). It seems that using JNI could be a nice way to do that quickly instead of building an IPC mechanism.
But after some research, I realized that the JNI is currently available only on Qt Android Extras module and we want to use JNI functions on our desktop application. Is there a different way to do that and take advantage of the QAndroidJniObject ? Any other ideas/alternatives on how to do that integration quickly between two applications? Also, I think that in Qt6 maybe it is possible to use JNI in other platforms other than Android but I am not very sure about that.
Thanks!
@nsourl
i think you missunderstood the mechanics of JNI.
Qt JNI works on Android because the Qt app also runs inside the JAVA engine.You cannot use JNI to call any JAVA method in a Desktop environment.
-
@nsourl
i think you missunderstood the mechanics of JNI.
Qt JNI works on Android because the Qt app also runs inside the JAVA engine.You cannot use JNI to call any JAVA method in a Desktop environment.
thanks for your reply and as you said I had misunderstood the JNI usability. I was thinking that it could be something more generic but it isn't.
Do you have something in mind to suggest as a solution in my case? A classic C++ and Java socket communication could be a nice option? Or something more advanced like gRPC could be more useful?
Thanks.
@raven-worx said in Qt Java function call via JNI:
@nsourl
i think you missunderstood the mechanics of JNI.
Qt JNI works on Android because the Qt app also runs inside the JAVA engine.You cannot use JNI to call any JAVA method in a Desktop environment.
-
thanks for your reply and as you said I had misunderstood the JNI usability. I was thinking that it could be something more generic but it isn't.
Do you have something in mind to suggest as a solution in my case? A classic C++ and Java socket communication could be a nice option? Or something more advanced like gRPC could be more useful?
Thanks.
@raven-worx said in Qt Java function call via JNI:
@nsourl
i think you missunderstood the mechanics of JNI.
Qt JNI works on Android because the Qt app also runs inside the JAVA engine.You cannot use JNI to call any JAVA method in a Desktop environment.
@nsourl, that's easy! Create two application, one with Java and another with Qt and have send/receive in each of those. I did that once between an android (Java) app and C# for testing.
-
thanks for your reply and as you said I had misunderstood the JNI usability. I was thinking that it could be something more generic but it isn't.
Do you have something in mind to suggest as a solution in my case? A classic C++ and Java socket communication could be a nice option? Or something more advanced like gRPC could be more useful?
Thanks.
@raven-worx said in Qt Java function call via JNI:
@nsourl
i think you missunderstood the mechanics of JNI.
Qt JNI works on Android because the Qt app also runs inside the JAVA engine.You cannot use JNI to call any JAVA method in a Desktop environment.
@nsourl
yes, any IPC mechnism is applicable for you.
https://doc.qt.io/qt-5/ipc.html
I would say take the one which integrates the easiest for your needs on both sides.
For example TCP/IP works in all frameworks and systems, but requires to setup a custom protocol for data transfer.Or use a RPC lib as you mentioned.