The items views in QML (TableView, TreeView) handles selection through ItemSelectionModel (QItemSelectionModel). This API works fine when the application is only interested in querying the selection model about the current selection. But if you need to manipulate the selection, the API is more "read-only". The current solution is to go through the QItemSelectionModel API in C++ instead, but documentation like https://doc.qt.io/qt-6/qml-qtqml-models-itemselectionmodel.html doesn't say anything about that.
We should improve the documentation in (at least) the mentioned file to e.g show an example of how you can create and manipulate a selection from QML/C++.