[][src]Struct qt_qml::QQmlPropertyMap

#[repr(C)]pub struct QQmlPropertyMap { /* fields omitted */ }

QQmlPropertyMap provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.

C++ class: QQmlPropertyMap.

C++ documentation:

QQmlPropertyMap provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.

In the C++ file:

// create our data QQmlPropertyMap ownerData; ownerData.insert("name", QVariant(QString("John Smith"))); ownerData.insert("phone", QVariant(QString("555-5555")));

// expose it to the UI layer QQuickView view; QQmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("owner", &ownerData);

view.setSource(QUrl::fromLocalFile("main.qml")); view.show();

Then, in main.qml:

Text { text: owner.name + " " + owner.phone }

The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.

To detect value changes made in the UI layer you can connect to the valueChanged() signal. However, note that valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

Note: It is not possible to remove keys from the map; once a key has been added, you can only modify or clear its associated value.

Note: When deriving a class from QQmlPropertyMap, use the protected two-argument constructor which ensures that the class is correctly registered with the Qt Meta-Object System.

Methods

impl QQmlPropertyMap[src]

pub fn value_changed(&self) -> Signal<(*const QString, *const QVariant)>[src]

This signal is emitted whenever one of the values in the map is changed. key is the key corresponding to the value that was changed.

Returns a built-in Qt signal QQmlPropertyMap::valueChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted whenever one of the values in the map is changed. key is the key corresponding to the value that was changed.

Note: valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

pub unsafe fn clear(&self, key: impl CastInto<Ref<QString>>)[src]

Clears the value (if any) associated with key.

Calls C++ function: void QQmlPropertyMap::clear(const QString& key).

C++ documentation:

Clears the value (if any) associated with key.

pub unsafe fn contains(&self, key: impl CastInto<Ref<QString>>) -> bool[src]

Returns true if the map contains key.

Calls C++ function: bool QQmlPropertyMap::contains(const QString& key) const.

C++ documentation:

Returns true if the map contains key.

See also size().

pub unsafe fn count(&self) -> c_int[src]

This is an overloaded function.

Calls C++ function: int QQmlPropertyMap::count() const.

C++ documentation:

This is an overloaded function.

Same as size().

pub unsafe fn index_mut(
    &self,
    key: impl CastInto<Ref<QString>>
) -> Ref<QVariant>
[src]

Returns the value associated with the key key as a modifiable reference.

Calls C++ function: QVariant& QQmlPropertyMap::operator[](const QString& key).

C++ documentation:

Returns the value associated with the key key as a modifiable reference.

If the map contains no item with key key, the function inserts an invalid QVariant into the map with key key, and returns a reference to it.

See also insert() and value().

pub unsafe fn index(&self, key: impl CastInto<Ref<QString>>) -> CppBox<QVariant>[src]

This is an overloaded function.

Calls C++ function: QVariant QQmlPropertyMap::operator[](const QString& key) const.

C++ documentation:

This is an overloaded function.

Same as value().

pub unsafe fn insert(
    &self,
    key: impl CastInto<Ref<QString>>,
    value: impl CastInto<Ref<QVariant>>
)
[src]

Sets the value associated with key to value.

Calls C++ function: void QQmlPropertyMap::insert(const QString& key, const QVariant& value).

C++ documentation:

Sets the value associated with key to value.

If the key doesn't exist, it is automatically created.

pub unsafe fn is_empty(&self) -> bool[src]

Returns true if the map contains no keys; otherwise returns false.

Calls C++ function: bool QQmlPropertyMap::isEmpty() const.

C++ documentation:

Returns true if the map contains no keys; otherwise returns false.

See also size().

pub unsafe fn keys(&self) -> CppBox<QStringList>[src]

Returns the list of keys.

Calls C++ function: QStringList QQmlPropertyMap::keys() const.

C++ documentation:

Returns the list of keys.

Keys that have been cleared will still appear in this list, even though their associated values are invalid QVariants.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QQmlPropertyMap::metaObject() const.

pub unsafe fn new_1a(
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QQmlPropertyMap>
[src]

Constructs a bindable map with parent object parent.

Calls C++ function: [constructor] void QQmlPropertyMap::QQmlPropertyMap(QObject* parent = …).

C++ documentation:

Constructs a bindable map with parent object parent.

pub unsafe fn new_0a() -> QBox<QQmlPropertyMap>[src]

QQmlPropertyMap provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.

Calls C++ function: [constructor] void QQmlPropertyMap::QQmlPropertyMap().

C++ documentation:

QQmlPropertyMap provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.

In the C++ file:

// create our data QQmlPropertyMap ownerData; ownerData.insert("name", QVariant(QString("John Smith"))); ownerData.insert("phone", QVariant(QString("555-5555")));

// expose it to the UI layer QQuickView view; QQmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("owner", &ownerData);

view.setSource(QUrl::fromLocalFile("main.qml")); view.show();

Then, in main.qml:

Text { text: owner.name + " " + owner.phone }

The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.

To detect value changes made in the UI layer you can connect to the valueChanged() signal. However, note that valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

Note: It is not possible to remove keys from the map; once a key has been added, you can only modify or clear its associated value.

Note: When deriving a class from QQmlPropertyMap, use the protected two-argument constructor which ensures that the class is correctly registered with the Qt Meta-Object System.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QQmlPropertyMap::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QQmlPropertyMap::qt_metacast(const char* arg1).

pub unsafe fn size(&self) -> c_int[src]

Returns the number of keys in the map.

Calls C++ function: int QQmlPropertyMap::size() const.

C++ documentation:

Returns the number of keys in the map.

See also isEmpty() and count().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QQmlPropertyMap::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QQmlPropertyMap::trUtf8(const char* s, const char* c, int n).

pub unsafe fn value(&self, key: impl CastInto<Ref<QString>>) -> CppBox<QVariant>[src]

Returns the value associated with key.

Calls C++ function: QVariant QQmlPropertyMap::value(const QString& key) const.

C++ documentation:

Returns the value associated with key.

If no value has been set for this key (or if the value has been cleared), an invalid QVariant is returned.

Trait Implementations

impl CppDeletable for QQmlPropertyMap[src]

unsafe fn delete(&self)[src]

Destroys the bindable map.

Calls C++ function: virtual [destructor] void QQmlPropertyMap::~QQmlPropertyMap().

C++ documentation:

Destroys the bindable map.

impl Deref for QQmlPropertyMap[src]

type Target = QObject

The resulting type after dereferencing.

fn deref(&self) -> &QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QQmlPropertyMap* ptr).

impl DynamicCast<QQmlPropertyMap> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QQmlPropertyMap>[src]

Calls C++ function: QQmlPropertyMap* dynamic_cast<QQmlPropertyMap*>(QObject* ptr).

impl Size for QQmlPropertyMap[src]

unsafe fn size(&self) -> usize[src]

Returns the number of keys in the map.

Calls C++ function: int QQmlPropertyMap::size() const.

C++ documentation:

Returns the number of keys in the map.

See also isEmpty() and count().

impl StaticDowncast<QQmlPropertyMap> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QQmlPropertyMap>[src]

Calls C++ function: QQmlPropertyMap* static_cast<QQmlPropertyMap*>(QObject* ptr).

impl StaticUpcast<QObject> for QQmlPropertyMap[src]

unsafe fn static_upcast(ptr: Ptr<QQmlPropertyMap>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QQmlPropertyMap* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.