Skip to main content

QPropertyMember

Trait QPropertyMember 

Source
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:

You will not need to implement this trait yourself; adding support for custom types requires CXX/C++ bindings.

Required Methods§

Source

fn qmetatype() -> QMetaType

Source

unsafe fn to_qvariant<Owner>(&self, owner: &Owner) -> QVariant
where 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.

Source

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).

Source

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§

Source

unsafe fn to_qvariant_view<Owner, Notify>( &self, owner: &Owner, notify: Notify, ) -> QVariant
where 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.

Implementations on Foreign Types§

Source§

impl<T> QPropertyMember for Rc<RefCell<T>>
where T: QObjectHolder,

Source§

fn qmetatype() -> QMetaType

Source§

unsafe fn to_qvariant<Owner>(&self, _owner: &Owner) -> QVariant
where Owner: QObjectHolder,

Source§

unsafe fn from_qvariant(value: &QVariant) -> Result<Rc<RefCell<T>>, ()>

Source§

fn property_eq(&self, other: &Rc<RefCell<T>>) -> bool

Source§

impl<T> QPropertyMember for Vec<Rc<RefCell<T>>>
where T: QmlElement,

Source§

fn qmetatype() -> QMetaType

Source§

unsafe fn to_qvariant<Owner>(&self, owner: &Owner) -> QVariant
where Owner: QObjectHolder,

Source§

unsafe fn to_qvariant_view<Owner, Notify>( &self, owner: &Owner, notify: Notify, ) -> QVariant
where Owner: QObjectHolder, Notify: Fn(&mut Owner) + 'static,

Source§

unsafe fn from_qvariant(_value: &QVariant) -> Result<Vec<Rc<RefCell<T>>>, ()>

Source§

fn property_eq(&self, other: &Vec<Rc<RefCell<T>>>) -> bool

Implementors§