On this page

QRangeModelAdapter::DataReference Struct

struct QRangeModelAdapter::DataReference

DataReference is a reference wrapper around an item in a QRangeModel. More...

This struct is under development and is subject to change.

This struct was introduced in Qt 6.11.

Public Types

Public Functions

DataReference(const QModelIndex &index)
DataReference(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)
DataReference(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)
QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type get() const
bool isValid() const
operator QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type() const
QRangeModelAdapter<Range, Protocol, Model>::DataReference::pointer operator->() const
QRangeModelAdapter<Range, Protocol, Model>::DataReference &operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)
QRangeModelAdapter<Range, Protocol, Model>::DataReference &operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &&value)
QRangeModelAdapter<Range, Protocol, Model>::DataReference &operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)
QRangeModelAdapter<Range, Protocol, Model>::DataReference &operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &value)

Detailed Description

Accessing an item in the model using the non-const overloads of at(), subscript operator[], or dereferencing a non-const iterator, returns a DataReference wrapper around the item in the model.

Assigning to that reference wrapper changes the data in the model using QAbstractItemModel API.

adapter[0] = newValue;

A const version of the value itself can be accessed using get() or operator->().

QRangeModelAdapter adapter(QList<Gadget>{ ~~~ });
auto value = adapter[0]->value();
// adapter[0]->setValue(); // not allowed - would not emit dataChanged()

In contrast to std::reference_wrapper, assigning one DataReference to another does not rebind the reference, but sets the value using copy- semantics.

adapter[0] = adapter[1]; // items at row 0 and row 1 now have the same value

See also RowReference and ConstRowReference.

Member Type Documentation

[alias] DataReference::const_value_type

An alias for the const type of the items stored in the underlying range. If different columns in the model hold different types, then this is an alias to const QVariant.

[alias] DataReference::pointer

An alias for the pointer type returned by operator->().

[alias] DataReference::value_type

An alias for the type of the items stored in the underlying range. If different columns in the model hold different types, then this is an alias to QVariant.

Member Function Documentation

[explicit noexcept] DataReference::DataReference(const QModelIndex &index)

Constructs a DataReference wrapper for the item at index.

DataReference::DataReference(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)

Constructs a copy of other.

DataReference::DataReference(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)

Constructs a DataReference by moving from other.

QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type DataReference::get() const

DataReference::operator QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type() const

Returns the item value referred to by this DataReference as a const value.

bool DataReference::isValid() const

Returns true if this DataReference refers to a valid model index.

QRangeModelAdapter<Range, Protocol, Model>::DataReference::pointer DataReference::operator->() const

Returns a pointer to the value referred to by this DataReference.

QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)

Moves the value reference by other into the value referenced by this wrapper.

QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &&value)

Move-assigns value to the underlying model item.

QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)

Assigns the item value referred to by other to the value referenced by this wrapper.

QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &value)

Assigns value to the underlying model item.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.