Skip to content

slint::VectorModel Class

template <typename ModelData>
class VectorModel;
C++
#include <slint.h>
C++

Inherits slint::Model.

A Model backed by a SharedVector.

slint::VectorModel<ModelData>::VectorModel()=default

Constructs a new empty VectorModel.

slint::VectorModel<ModelData>::VectorModel(std::vector<ModelData> array)

Constructs a new VectorModel from array.

size_t slint::VectorModel<ModelData>::row_count() const override

The amount of row in the model.

std::optional<ModelData> slint::VectorModel<ModelData>::row_data(size_t i) const override

Returns the data for a particular row. This function should be called with row < row_count().

void slint::VectorModel<ModelData>::set_row_data(size_t i, const ModelData &value) override

Sets the data for a particular row.

This function should only be called with row < row_count().

If the model cannot support data changes, then it is ok to do nothing. The default implementation will print a warning to stderr.

If the model can update the data, it should also call row_changed

bool slint::VectorModel<ModelData>::remove_row(size_t index) override

Removes the row at the given index from the model. Returns true when the row was removed, false when the model rejected it.

The default implementation does nothing and returns false. A model that supports removing rows should also call notify_row_removed.

bool slint::VectorModel<ModelData>::insert_row(size_t index, const ModelData &value) override

Inserts a new row with the given data at the given index, shifting the following rows by one. Returns true when the row was inserted, false when the model rejected it.

The default implementation does nothing and returns false. A model that supports inserting rows should also call notify_row_added.

void slint::VectorModel<ModelData>::push_back(const ModelData &value)

Append a new row with the given value.

void slint::VectorModel<ModelData>::erase(size_t index)

Remove the row at the given index from the model.

void slint::VectorModel<ModelData>::insert(size_t index, const ModelData &value)

Inserts the given value as a new row at the specified index.

void slint::VectorModel<ModelData>::clear()

Erases all rows from the VectorModel.

void slint::VectorModel<ModelData>::set_vector(std::vector<ModelData> array)

Replaces the underlying VectorModel’s vector with array.


© 2026 SixtyFPS GmbH