What exactly is qsizetype and what is it's purpose?
-
As above. In QList, calling size() outputs a qsizetype. And according to the <QtGlobal> page, qsizetype is an "Integral type providing Posix' ssize_t for all platforms." Does that mean qsizetype can be treated like an int? And if it is, then why would this int need it's own class? If not, what are the main differences in application between int and qsizetype?
-
@Dummie1138 said:
Does that mean qsizetype can be treated like an int?
In the sense that it is an integer yes, but don't make assumptions that it has the same size as int.
And if it is, then why would this int need it's own class?
Qt uses signed integers for sizes. The standard size_t is unsigned , so it's not suitable. The ssize_t is signed, but it is not standard (it's a POSIX extension), so not available on all platforms. qsizetype is, like the docs say, platform independent ssize_t equivalent. And it's not a class. It's a typedef, so it might as well be an int underneath.
what are the main differences in application between int and qsizetype?
As I mentioned above it's a typedef, so on some platforms it might be exactly the same. But int has no defined size, only the minimum of 16 bits. It's usually 32 bit, but on some platforms it can be 16, 64,128 or some other exotic size. qsizetype is always the same size as size_t on given platform (which can vary too, but can differ from int).
As an example on 64bit Windows int is 32bit and qsizetype (and size_t) is 64bit, so you can't use them interchangeably for large sizes.