[Development] Renaming QGenericItemModel
Volker Hilsheimer
volker.hilsheimer at qt.io
Wed May 21 08:47:22 CEST 2025
> On 20 May 2025, at 12:50, Giuseppe D'Angelo <giuseppe.dangelo at kdab.com> wrote:
>
> On 20/05/2025 10:26, Richard Gustavsen wrote:
>> Would it be more convenient to put the range API directly on QRangeModel instead? E.g:
>> QRangeModel model({1, 2, 3, 4, 5});
>> listView.setModel(&model);
>> model.erase(model.begin());
>> model[0] = x;
>> model.push_back(y);
>
> Yes, this is an important question -- in order to understand the future of this API, and thus the name of the class.
It would of course be more convenient. But for that to work (ie. for us to know what model.begin() is, what operator[] returns, and what ‘y’ can be), QRangeModel has to be a template class.
And it isn’t, and shouldn’t be, as a subclass of a polymorphic type for the reasons discussed (weak vtables, and vtable bloat for each specialization).
The only alternative I see is making it a value type that can implicitly convert to a QAbstractItemModel *. But that’s then not a model itself, and shouldn’t be called “Model". It would then be a QRangeModelAdapter (although I wouldn’t want it to implicitly convert to QAbstractItemModel *).
Volker
More information about the Development
mailing list