[Qt-interest] Qt Containers (or: why I must use STL)
Ian Thomson
Ian.Thomson at iongeo.com
Tue Oct 13 15:27:54 CEST 2009
Stephen Bryant wrote:
> I'm afraid you've lost me on this one. How is 'int' simpler than 'size_t'?
> Why are there warnings? STL manages to have container::size_type defined
> as size_t, and I'm not seeing warnings for that on any of the platforms
> I'm building on. Is this limited to certain systems, perhaps?
The signals and slots mechanism can only connect up like types. For that
reason, all numeric values are 'int' to encourage compatibility between
different signals and slots and so on. Mixing in size_t would not help here.
This idea has been carried over to the Qt container formats. As Qt is
designed for creating GUI apps, most often the user code will be doing
things inside (or based on) slots which are called. These slots will
have integer parameters. Of course, passing an integer to a function
which requires a size_t will cause a compiler warning, and vice-versa.
This is troublesome to the coder and solutions with casts don't offer
any advantages over just using ints (you're still limited to max_int)
and actually reduces the ability to detect bad values (e.g. asserting
the value is not less than 0).
Cheers,
Ian.
More information about the Qt-interest-old
mailing list