Class QtRaaSApplication
QtRaaSApplication class serves as the Java-side entry point
for embedding a Qt-based Rendering as a Service (RaaS) application
into an Android environment.
It is responsible for:
- Loading the required Qt libraries and native components.
- Creating a service adapter when running outside of an Android Service context.
- Forwarding Android
SurfaceandMotionEventevents to the Qt runtime through JNI bindings.
This class is typically instantiated from an Android Service
to initialize and manage the Qt runtime environment and its surface-based rendering
pipeline.
-
Constructor Summary
ConstructorsConstructorDescriptionQtRaaSApplication(android.content.Context context) Constructs aQtRaaSApplicationinstance using the given context, and loads the default Qt main library.QtRaaSApplication(android.content.Context context, String mainLibraryName) Constructs a newQtRaaSApplicationinstance. -
Method Summary
Modifier and TypeMethodDescription<T> TgetProperty(String propertyName) Gets the value of an existing property of the QML root object.org.qtproject.qt.android.QtQmlStatusGets the status of the QML component.voidsendTouchEvent(android.view.MotionEvent event, String itemId) Forwards aMotionEventfrom Android to the corresponding Qt Quick item identified byitemId.voidsetProperty(String propertyName, Object value) Sets the value of an existing property on the QML root object.voidsetStatusChangeListener(org.qtproject.qt.android.QtQmlStatusChangeListener listener) Sets a QtQmlStatusChangeListener to listen to status changes.voidsetSurface(android.view.Surface surface, String itemId) Sets a new AndroidSurfaceto be associated with a Qt Quick item identified by the givenitemId.voidunsetSurface(String itemId) Unsets the surface that was previously associated with the Qt Quick item identified by the givenitemId.
-
Constructor Details
-
QtRaaSApplication
Constructs a newQtRaaSApplicationinstance.This constructor initializes and loads the Qt runtime environment using the provided
Contextand the name of the main Qt library.- Parameters:
context- the Android contextmainLibraryName- the main Qt library name (without prefix/suffix).
-
QtRaaSApplication
public QtRaaSApplication(android.content.Context context) Constructs aQtRaaSApplicationinstance using the given context, and loads the default Qt main library.- Parameters:
context- the Android context or service
-
-
Method Details
-
setSurface
Sets a new AndroidSurfaceto be associated with a Qt Quick item identified by the givenitemId.This native method forwards the provided surface handle to the Qt side, where it is mapped to the corresponding item and used for rendering through the
QAndroidSurfaceRenderEngine.- Parameters:
surface- the Android surface object to associateitemId- the id of the Qt Quick itemNotes:
- This method is implemented in native (C++) code.
- If
itemIdis invalid, this method will fail with a warning. - Passing an invalid
surfaceresults in undefined behavior. - Passing
nullas thesurfaceis equivalent to callingunsetSurface(String).
- See Also:
-
sendTouchEvent
Forwards aMotionEventfrom Android to the corresponding Qt Quick item identified byitemId.This method retrieves and handles touch input forwarding to the Qt side for the specified item.
- Parameters:
event- the Android touch motion event to senditemId- the id of the Qt Quick item that receives the event
-
unsetSurface
Unsets the surface that was previously associated with the Qt Quick item identified by the givenitemId.This method forwards a
nullsurface to the Qt side to stop rendering the item on the surface that was previously associated with it.- Parameters:
itemId- the id of the Qt Quick itemNote: It is crucial to call this method when the surface is about to be destroyed.
-
getStatus
public org.qtproject.qt.android.QtQmlStatus getStatus()Gets the status of the QML component.- Returns:
- Returns
READYwhen the QML component is ready. It can also returnNULLorERRORbased on the status of the underlying QQmlEngine instance.
-
setStatusChangeListener
public void setStatusChangeListener(org.qtproject.qt.android.QtQmlStatusChangeListener listener) Sets a QtQmlStatusChangeListener to listen to status changes.- Parameters:
listener- an instance of a QtQmlStatusChangeListener interface
-
setProperty
Sets the value of an existing property on the QML root object. The supported types areInteger,Double,Float,BooleanandString. These types get converted to their corresponding QML types int, double/float, bool and string. This function does not add properties to the QML root object if they do not exist, but prints a warning.- Parameters:
propertyName- the name of the existing root object property to set the value ofvalue- the value to set the property to QML's int, double/float, bool or string- See Also:
-
getProperty
Gets the value of an existing property of the QML root object. The supported types areInteger,Double,Float,BooleanandString. These types get converted to their corresponding QML types int, double/float, bool and string. If the property does not exist or the status of the QML component is anything other thanREADY, this function will return null.- Parameters:
propertyName- the name of the existing root object property- Throws:
ClassCastException- if the returned type could not be casted to the requested type.- See Also:
-