pub trait QPropertyMember: Sized {
// Required methods
fn qmetatype() -> QMetaType;
unsafe fn to_qvariant<Owner>(&self, owner: &Owner) -> QVariant
where Owner: QObjectHolder;
unsafe fn from_qvariant(value: &QVariant) -> Result<Self, ()>;
fn property_eq(&self, other: &Self) -> bool;
// Provided method
unsafe fn to_qvariant_view<Owner, Notify>(
&self,
owner: &Owner,
notify: Notify,
) -> QVariant
where Owner: QObjectHolder,
Notify: Fn(&mut Owner) + 'static { ... }
}Expand description
Enables a type to be used as a property.
Implemented for:
- Primitive numeric types and
bool StringVec<T>whereTis one of the aboveRc<RefCell<T>>whereTimplements [QObjectHolder]Vec<Rc<RefCell<T>>>whereTimplementsQmlElement
You will not need to implement this trait yourself; adding support for custom types requires CXX/C++ bindings.
Required Methods§
fn qmetatype() -> QMetaType
Sourceunsafe fn to_qvariant<Owner>(&self, owner: &Owner) -> QVariantwhere
Owner: QObjectHolder,
unsafe fn to_qvariant<Owner>(&self, owner: &Owner) -> QVariantwhere
Owner: QObjectHolder,
Returns a QVariant representation of self for read operations.
Owner is the [QObjectHolder] that holds this property; passing it
allows returning views onto its members and borrowing correctly on
access. If the member is passed by value, owner can be ignored.
§Safety
For QObject-backed members the returned QVariant carries a raw,
untracked QObject*: the caller must consume it and start tracking
its state immediately, before any garbage collector can run. The
metaobject dispatch upholds this by consuming the variant within
the same call stack. See from_qvariant.
Sourceunsafe fn from_qvariant(value: &QVariant) -> Result<Self, ()>
unsafe fn from_qvariant(value: &QVariant) -> Result<Self, ()>
Converts value into the concrete type, used for write operations.
§Safety
For QObject-backed members this reads a raw QObject* out of the
variant and dereferences it: the caller must guarantee the variant
genuinely holds a live QObject of a compatible type. The metaobject
dispatch upholds this (Qt type-checks the property write).
Sourcefn property_eq(&self, other: &Self) -> bool
fn property_eq(&self, other: &Self) -> bool
Returns true if self and other are equal.
Used to decide whether the notify signal should be emitted and the
stored value replaced on a property write.
Provided Methods§
Sourceunsafe fn to_qvariant_view<Owner, Notify>(
&self,
owner: &Owner,
notify: Notify,
) -> QVariantwhere
Owner: QObjectHolder,
Notify: Fn(&mut Owner) + 'static,
unsafe fn to_qvariant_view<Owner, Notify>(
&self,
owner: &Owner,
notify: Notify,
) -> QVariantwhere
Owner: QObjectHolder,
Notify: Fn(&mut Owner) + 'static,
Returns a QVariant view of self for read operations, with access to
the property’s notify signal. Unlike to_qvariant,
this variant can return a live view that emits notify when the
underlying data changes.
The default implementation ignores notify and falls back to
to_qvariant.
§Safety
Same untracked-pointer contract as to_qvariant.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.