[Development] QAbstractItemModel::createIndex(void const*)?

Jean-Michaƫl Celerier jeanmichael.celerier at gmail.com
Tue Nov 27 19:39:57 CET 2018


I had this exact "problem" today :

> Usually the data is contained in a non-const object, presumably in the
model itself, so the pointer isn't ordinarily pointing to an immutable
object.

sure, but the methods that generally call createIndex
(QAbstractItemModel::index for instance) are const, so your members are
const too, so you have to const_cast<T*>(&m_data.getMyObject(row, column));




On Tue, Nov 27, 2018 at 6:50 PM Konstantin Shegunov <kshegunov at gmail.com>
wrote:

> Hi,
>
> On Tue, Nov 27, 2018 at 7:41 PM Matthew Woehlke <mwoehlke.floss at gmail.com>
> wrote:
>
>> But... why *isn't* there such an overload?
>
>
> Your object is const, so the implicit cast to void * fails.
>
>
>> Is there any reason not to add one?
>
>
> I'd say the question is rather, is there really a reason to add one?
>
> Usually the data is contained in a non-const object, presumably in the
> model itself, so the pointer isn't ordinarily pointing to an immutable
> object.
> Do you need to enforce the const?
>
> Kind regards.
> _______________________________________________
> Development mailing list
> Development at lists.qt-project.org
> https://lists.qt-project.org/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181127/1509dd3c/attachment.html>


More information about the Development mailing list