The non const overloads of first() and last() do detach
if the reference count is higher than 1.
Therefore we use constFirst() and constLast() instead.
Change-Id: I737cfc428f1c21f16185b9b51175e181c0ec7068
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>