Creating only one QJniEnvironment object. How?
-
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.
-
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.
The documentation states that the
QJniEnvironmenttype is some kind of wrapper for the Java nativeJNIEnvenvironment 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 multipleJNIEnvin 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 threadQJniEnvironment::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
-
@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.
-
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.
@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.