Table of Contents

Class QmlElementAttribute

Namespace
Qt.Quick
Assembly
Qt.Bridge.CSharp.Api.dll

Marks a type as a QML element and configures how Qt Bridge registers it with QML.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, Inherited = false)]
public class QmlElementAttribute : Attribute
Inheritance
QmlElementAttribute
Derived
Inherited Members

Remarks

Apply this attribute to a class, struct, or interface to make the type visible to the Qt Bridge QML generation pipeline even when it is declared outside the main source assembly. Use Name to override the default QML type name and Singleton to register the type as a QML singleton.

[QmlElement(Name = "Counter", Singleton = true)]
public class CounterService
{
    public int Clicks { get; set; }
}

In QML, the type is exposed under the name Counter. Because it is registered as a singleton, it is intended to be shared as one instance rather than created repeatedly.

Text {
    text: Counter.clicks
}

Properties

Name

Gets or sets the QML name used when the annotated type is registered.

public string Name { get; set; }

Property Value

string

Remarks

When omitted, the generator uses the default element name for the type. If specified, the name must be a valid QML type name and must start with an uppercase letter and then contain only letters, digits, or underscores.

Singleton

Gets or sets whether the annotated type should be registered as a QML singleton.

public bool Singleton { get; set; }

Property Value

bool

Remarks

A QML singleton is a type that QML exposes as one shared instance for the whole QML engine, similar in intent to an application-wide service. Use this for service or utility objects that should be shared rather than instantiated repeatedly from QML.