Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Java function call via JNI
Qt 6.11 is out! See what's new in the release blog

Qt Java function call via JNI

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • N Offline
    N Offline
    nsourl
    wrote on last edited by
    #1

    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!

    raven-worxR 1 Reply Last reply
    1
    • N nsourl

      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!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      N 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @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.

        N Offline
        N Offline
        nsourl
        wrote on last edited by
        #3

        @raven-worx

        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.

        D raven-worxR 2 Replies Last reply
        0
        • N nsourl

          @raven-worx

          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.

          D Offline
          D Offline
          deleted385
          wrote on last edited by deleted385
          #4

          @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.

          1 Reply Last reply
          0
          • N nsourl

            @raven-worx

            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.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @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.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

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