Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Creating only one QJniEnvironment object. How?
Forum Updated to NodeBB v4.3 + New Features

Creating only one QJniEnvironment object. How?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 218 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.
  • B Offline
    B Offline
    bogong
    wrote last edited by
    #1

    Hello all?

    Trying to find info about QJniEnvironment object type. Is it singleton? Will it be multiplied if there will be multiple constructor calls? Or multiple constructors will be referring to the same object in memory? What is there correct way to create QJniEnvironment object?

    In this documentation https://doc.qt.io/qt-6.8/qjnienvironment.html#QJniEnvironment haven't found anything about it.

    Pl45m4P V 2 Replies Last reply
    0
    • B bogong

      Hello all?

      Trying to find info about QJniEnvironment object type. Is it singleton? Will it be multiplied if there will be multiple constructor calls? Or multiple constructors will be referring to the same object in memory? What is there correct way to create QJniEnvironment object?

      In this documentation https://doc.qt.io/qt-6.8/qjnienvironment.html#QJniEnvironment haven't found anything about it.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by Pl45m4
      #2

      @bogong

      The documentation states that the QJniEnvironment type is some kind of wrapper for the Java native JNIEnv environment type, with more convenient and error checking functions added to it.

      Or multiple constructors will be referring to the same object in memory?

      In general, when some class is a singleton or uses shared memory concepts this would usually be mentioned in the Qt documentation (assuming the man. page is complete and up-to-date)
      So I think, no.
      Is it possible to have multiple JNIEnv in Java on Android?

      @bogong said in Creating only one QJniEnvironment object. How?:

      What is there correct way to create QJniEnvironment object?

      Isn't the constructor self-explanatory?!
      I think you call the constructor and it automatically initializes in the background and connects with the JavaVM/ JNI in the same thread

      QJniEnvironment::QJniEnvironment()

      Constructs a new JNI Environment object and attaches the current thread to the Java VM.

      [noexcept] QJniEnvironment::~QJniEnvironment()

      Detaches the current thread from the Java VM and destroys the QJniEnvironment object. This will clear any pending exception by calling checkAndClearExceptions().

      After that you can retrieve the native Java objects or use the Qt type to do the mentioned error handling and checks.

      Don't ask me any further, I've never used this :D


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bogong
        wrote last edited by
        #3

        Don't ask me any further, I've never used this :D

        Why writing if never used it???

        Pl45m4P 1 Reply Last reply
        0
        • B bogong

          Don't ask me any further, I've never used this :D

          Why writing if never used it???

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote last edited by Pl45m4
          #4

          @bogong said in Creating only one QJniEnvironment object. How?:

          Why writing if never used it???

          Why asking, when it's well documented what it does?

          Edit:

          The least you can do is check the implementation before asking.

          • https://github.com/qt/qtbase/blob/dev/src/corelib/kernel/qjnienvironment.cpp

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • B bogong

            Hello all?

            Trying to find info about QJniEnvironment object type. Is it singleton? Will it be multiplied if there will be multiple constructor calls? Or multiple constructors will be referring to the same object in memory? What is there correct way to create QJniEnvironment object?

            In this documentation https://doc.qt.io/qt-6.8/qjnienvironment.html#QJniEnvironment haven't found anything about it.

            V Offline
            V Offline
            Ville Voutilainen
            wrote last edited by
            #5

            @bogong Hello, a JNIEnv* is thread-specific, and a QJniEnvironment object wraps the current thread's env. You can have as many copies or separate instances you like, and they all refer to the same object in memory. It's relatively light-weight, so you can just default-construct one whenever you need one. The separate QJniEnvironment instances also refer to the same caches in memory, such as caches for resolved classes and methods, as those are stored in thread-local storage.

            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