QtJniTypes::JObject Class
template <typename Type> class QtJniTypes::JObjectIl modello JObject nel namespace QtJniTypes costituisce la base dei tipi Java dichiarati. Per saperne di più...
| Intestazione: | #include <qjniobject.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| A partire da: | Qt 6.8 |
Funzioni pubbliche
| JObject() | |
| JObject(QJniObject &&other) | |
| JObject(const QJniObject &other) | |
| JObject(jobject other) | |
| JObject(const QtJniTypes::JObject<Type> &other) | |
| JObject(QtJniTypes::JObject<Type> &&other) | |
| ~JObject() | |
| auto | callMethod(const char *method, Args &&... args) const |
| QByteArray | className() const |
| auto | getField(const char *field) const |
| bool | isValid() const |
| jclass | objectClass() const |
| auto | setField(const char *field, T &&value) |
| QString | toString() const |
| QtJniTypes::JObject<Type> & | operator=(QtJniTypes::JObject<Type> &&other) |
| QtJniTypes::JObject<Type> & | operator=(const QtJniTypes::JObject<Type> &other) |
Membri pubblici statici
| auto | callStaticMethod(const char *methodName, Args &&... args) |
| QtJniTypes::JObject<Type> | construct(Args &&... args) |
| QtJniTypes::JObject<Type> | fromJObject(jobject object) |
| QtJniTypes::JObject<Type> | fromLocalRef(jobject ref) |
| auto | getStaticField(const char *field) |
| bool | isClassAvailable() |
| bool | registerNativeMethods(std::initializer_list<JNINativeMethod> methods) |
| auto | setStaticField(const char *field, T &&value) |
Descrizione dettagliata
JObject<Type> è una classe template in cui Type specifica il tipo Java rappresentato.
Questo modello viene specializzato quando si utilizza la macro Q_DECLARE_JNI_CLASS. La specializzazione produce un tipo univoco nello spazio dei nomi QtJniTypes. Ciò consente al sistema dei tipi di dedurre la firma corretta nelle chiamate JNI quando un'istanza del tipo specializzato viene passata come parametro.
Le istanze possono essere convertite implicitamente da e verso QJniObject e jobject e forniscono la stessa API del modello di QJniObject per chiamare metodi e accedere alle proprietà. Poiché le istanze di JObject conoscono il tipo Java che contengono, le API per accedere a metodi o campi statici non richiedono il nome della classe come parametro esplicito.
Vedi anche Q_DECLARE_JNI_CLASS.
Documentazione sulle funzioni membro
JObject::JObject()
Crea un'istanza di JObject tramite il costruttore predefinito. In questo modo viene creata anche un'istanza del tipo Java rappresentato tramite il costruttore predefinito.
[noexcept] JObject::JObject(QJniObject &&other)
Crea un’istanza di JObject a partire da other.
JObject::JObject(const QJniObject &other)
Crea un'istanza di JObject che contiene un riferimento allo stesso JObject presente all'indirizzo other.
JObject::JObject(jobject other)
Crea un'istanza di JObject che contiene un riferimento a other.
[default] JObject::JObject(const QtJniTypes::JObject<Type> &other)
Crea una copia di un'istanza di ` JObject`.
[noexcept default] JObject::JObject(QtJniTypes::JObject<Type> &&other)
Crea un'istanza di ` JObject` tramite il costrutto `move`.
[default] JObject::~JObject()
Elimina l'istanza di JObject.
template <typename Ret = void, typename... Args> auto JObject::callMethod(const char *method, Args &&... args) const
Chiama il metodo di istanza ` method ` con gli argomenti ` args` e restituisce il risultato di tipo `Ret` (a meno che `Ret` non sia di tipo ` void`). Se `Ret` è di tipo `jobject`, il valore restituito sarà un ` QJniObject`.
Vedi anche ` QJniObject::callMethod()`.
[static] template <typename Ret = void, typename... Args> auto JObject::callStaticMethod(const char *methodName, Args &&... args)
Chiama il metodo statico ` methodName ` con gli argomenti ` args` e restituisce il risultato di tipo `Ret` (a meno che `Ret` non sia ` void`). Se `Ret` è un tipo `jobject`, il valore restituito sarà un ` QJniObject`.
Vedi anche QJniObject::callStaticMethod().
QByteArray JObject::className() const
Restituisce il nome della classe Java di cui questo oggetto è un'istanza.
Vedi anche objectClass() e QJniObject::className().
[static] template <typename... Args> QtJniTypes::JObject<Type> JObject::construct(Args &&... args)
Crea un oggetto Java a partire da ` args ` e restituisce un'istanza di ` JObject ` che contiene un riferimento a tale oggetto Java.
[static] QtJniTypes::JObject<Type> JObject::fromJObject(jobject object)
Crea un'istanza di ` JObject ` a partire da ` object ` e restituisce tale istanza.
[static] QtJniTypes::JObject<Type> JObject::fromLocalRef(jobject ref)
Crea un oggetto ` JObject ` che contiene un riferimento locale a ` ref` e restituisce tale oggetto.
template <typename T> auto JObject::getField(const char *field) const
Restituisce il valore del campo di istanza ` field`.
Vedi anche QJniObject::getField().
[static] template <typename T> auto JObject::getStaticField(const char *field)
Restituisce il valore del campo statico ` field`.
Vedi anche ` QJniObject::getStaticField()`.
[static] bool JObject::isClassAvailable()
Restituisce se la classe rappresentata da questa specializzazione di ` JObject ` è disponibile.
Vedi anche QJniObject::isClassAvailable().
bool JObject::isValid() const
Restituisce se l'istanza di ` JObject ` contiene un riferimento valido a un `jobject`.
Vedi anche QJniObject::isValid().
jclass JObject::objectClass() const
Restituisce la classe Java di cui questa JObject è un'istanza, sotto forma di jclass.
Vedi anche className() e QJniObject::objectClass().
[static] bool JObject::registerNativeMethods(std::initializer_list<JNINativeMethod> methods)
Registra i metodi Java in methods con la classe Java rappresentata dalla specializzazione JObject e restituisce se la registrazione è andata a buon fine.
Vedi anche QJniEnvironment::registerNativeMethods().
template <typename Ret = void, typename T> auto JObject::setField(const char *field, T &&value)
Imposta il valore del campo di istanza ` field ` su ` value`.
Vedi anche QJniObject::setField().
[static] template <typename Ret = void, typename T> auto JObject::setStaticField(const char *field, T &&value)
Imposta il campo statico ` field ` su ` value`.
Vedi anche QJniObject::setStaticField().
QString JObject::toString() const
Restituisce un oggetto ` QString ` contenente una rappresentazione stringa dell’oggetto Java.
Vedi anche QJniObject::toString().
[noexcept default] QtJniTypes::JObject<Type> &JObject::operator=(QtJniTypes::JObject<Type> &&other)
Assegna other a questa istanza di JObject.
[default] QtJniTypes::JObject<Type> &JObject::operator=(const QtJniTypes::JObject<Type> &other)
Assegna “ other ” a questa istanza di “ JObject ”.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.