[Development] QtCS2019 Notes: QtCore

André Pönitz apoenitz at t-online.de
Sat Nov 23 13:55:52 CET 2019


On Sat, Nov 23, 2019 at 12:48:12PM +0100, Thiago Macieira wrote:
> On Saturday, 23 November 2019 09:47:23 CET André Pönitz wrote:
> > So let's make this a real proposal: Should we have
> > 
> >    qsizetype QContainer::size()
> >    int QContainer::count() const
> 
> So you propose changing code like
> 
> 	int n = vec.size();
> to
> 	int n = vec.count();
> while we could just change it to:
> 	int n = int(vec.size());
> 
> If we're going to make changes anyway, why not make the right change?

    int n = vec.count();

is less ugly than

    int n = int(vec.size());

It's less to type, less to read, one level of parantheses less.

Also, replacing size() by count() would be easy to do in e.g. Creator
(effectively a single global renaming of size() to count() and discarding the
changes to Qt itself).

Wrapping int() around requires more manual work.

Peppe has a point that the problem exists for other functions like indexOf(),
but e.g. in Creator code that's used far less frequently than size() (about an
order of magnitude less) so having to use int(indexOf(...)) is less of a pain
than the .size() case.

Andre'


More information about the Development mailing list