slint::Model Class
template <typename ModelData>class Model;#include <slint.h>Inherited by slint::FilterModel
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.
Public Functions
Section titled “Public Functions” ~Model (virtual)
Section titled “ ~Model (virtual)”slint::Model<ModelData>::~Model()=default
slint::Model<ModelData>::Model()=default
slint::Model<ModelData>::Model(const Model &)=delete
operator=
Section titled “ operator=”Model & slint::Model<ModelData>::operator=(const Model &)=delete
row_count (pure virtual)
Section titled “ row_count (pure virtual)”size_t slint::Model<ModelData>::row_count() const =0
The amount of row in the model.
row_data (pure virtual)
Section titled “ row_data (pure virtual)”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().
set_row_data (virtual)
Section titled “ set_row_data (virtual)”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
push_row (virtual)
Section titled “ push_row (virtual)”void slint::Model<ModelData>::push_row(const ModelData &)
Adds a new row with the given data at the end of the model.
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 notify_row_added
remove_row (virtual)
Section titled “ remove_row (virtual)”void slint::Model<ModelData>::remove_row(std::ptrdiff_t)
Removes the row at the given index from the model.
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 notify_row_removed
insert_row (virtual)
Section titled “ insert_row (virtual)”void slint::Model<ModelData>::insert_row(std::ptrdiff_t, const ModelData &)
Inserts a new row with the given data at the given index, shifting the following rows by one.
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 notify_row_added
Protected Functions
Section titled “Protected Functions” notify_row_changed
Section titled “ notify_row_changed”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.
notify_row_added
Section titled “ notify_row_added”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.
notify_row_removed
Section titled “ notify_row_removed”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.
notify_reset
Section titled “ notify_reset”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.
row_changed
Section titled “ row_changed”void slint::Model<ModelData>::row_changed(size_t row)
row_added
Section titled “ row_added”void slint::Model<ModelData>::row_added(size_t index, size_t count)
row_removed
Section titled “ row_removed”void slint::Model<ModelData>::row_removed(size_t index, size_t count)
void slint::Model<ModelData>::reset()© 2026 SixtyFPS GmbH