Interface IQmlElement
Provides QML component lifecycle callbacks for a generated Qt Bridge object.
public interface IQmlElement
Remarks
Implement this interface when a type needs notification during QML construction or when it needs access to nested QML child objects after the component has been completed. This is especially useful for parent-child composition patterns in QML, where a parent element needs to discover and wire up child elements declared inside it. Qt Bridge maps these members to the corresponding QQmlParserStatus lifecycle hooks in the generated adapter layer.
A common pattern is to use QmlComponentComplete(object[]) to discover nested child objects declared inside the element in QML and wire them to the parent service or controller object.
public class ApiResource
{
public string Path { get; set; }
internal ApiClient Client { get; set; }
}
public class ApiClient : IQmlElement
{
private List<ApiResource> Resources { get; } = new();
public void QmlClassBegin()
{ }
public void QmlComponentComplete(object[] nestedElements)
{
foreach (var element in nestedElements) {
if (element is not ApiResource resource)
continue;
Resources.Add(resource);
resource.Client = this;
}
}
}
With a C# type like the one above, QML can declare nested child objects inside the parent element:
ApiClient {
ApiResource {
path: "users"
}
ApiResource {
path: "orders"
}
}
When the QML component is complete, Qt Bridge passes those nested child objects to
QmlComponentComplete(object[]), where the implementation can inspect, cast,
and initialize them. In this example, the two ApiResource objects are child
elements composed inside ApiClient.
Methods
QmlClassBegin()
Called when QML begins constructing the object.
void QmlClassBegin()
Remarks
Use this callback for lightweight initialization that should happen before nested child objects are fully wired up.
QmlComponentComplete(object[])
Called after the QML component has been fully constructed.
void QmlComponentComplete(object[] nestedElements)
Parameters
nestedElementsobject[]The nested QML child objects collected by the generated bridge wrapper.
Remarks
This is the right place to inspect or wire up nested child objects declared inside the element in QML, for example service-specific helper or resource objects.