Skip to content

slint::Model Class

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

Inherited by slint::FilterModel, slint::MapModel<SourceModelData, MappedModelData>, slint::ReverseModel, slint::SortModel, slint::VectorModel.

A Model is providing Data for Slint Models or ListView elements of the .slint language

This is typically used in a std::shared_ptr<slint::Model>. Model is an abstract class and you can derive from it to provide your own data model, or use one of the provided models such as slint::VectorModel

An implementation of the Model can provide data to slint by re-implementing the row_count and row_data functions. It is the responsibility of the Model implementation to call the Model::notify_row_changed(), Model::notify_row_added(), Model::notify_row_removed(), or Model::notify_reset() functions when the underlying data changes.

Note that the Model is not thread-safe. All Model operations need to be done in the main thread. If you need to update the model data from another thread, use the slint::invoke_from_event_loop() function to send the data to the main thread and update the model.

slint::Model<ModelData>::~Model()=default
slint::Model<ModelData>::Model()=default
slint::Model<ModelData>::Model(const Model &)=delete
Model & slint::Model<ModelData>::operator=(const Model &)=delete
size_t slint::Model<ModelData>::row_count() const =0

The amount of row in the model.

std::optional<ModelData> slint::Model<ModelData>::row_data(size_t i) const =0

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

void slint::Model<ModelData>::set_row_data(size_t, const ModelData &)

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::Model<ModelData>::push_row(const ModelData &data)

Adds a new row with the given data at the end of the model. Returns true when the row was added, false when the model rejected it.

The default implementation inserts the row after the last one with insert_row, so implementing insert_row is enough to support push.

bool slint::Model<ModelData>::remove_row(size_t)

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::Model<ModelData>::insert_row(size_t, const ModelData &)

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::Model<ModelData>::notify_row_changed(size_t row)

Notify the views that a specific row was changed

Your model implementation should call this function after the data of a row changes.

void slint::Model<ModelData>::notify_row_added(size_t index, size_t count)

Notify the views that rows were added

Your model implementation should call this function after the row were added.

void slint::Model<ModelData>::notify_row_removed(size_t index, size_t count)

Notify the views that rows were removed

Your model implementation should call this function after the row were removed.

void slint::Model<ModelData>::notify_reset()

Notify the views that the model has been changed and that everything needs to be reloaded

Your model implementation should call this function after the model has been changed.

void slint::Model<ModelData>::row_changed(size_t row)
void slint::Model<ModelData>::row_added(size_t index, size_t count)
void slint::Model<ModelData>::row_removed(size_t index, size_t count)
void slint::Model<ModelData>::reset()

© 2026 SixtyFPS GmbH