QLists with signed int instead of unsigned int?
-
Why does QT use signed int for indexing an QList or other form of listed object?
QList<double> list; int index = 0; list[index] = 1.05;Arrays always start at Index 0, therefore I can't see any reason, why signed int is used.
The same applies for the return value of member functions like:list.size();The list can't be smaller than 0.
Is there any logical reason of taking signed values?
I have to convert them everywhere, because I use always unsigned values for things which can't handle negative numbers.Thanks for your answer
Alex -
Is there any logical reason of taking signed values?
Yes, e.g. to be able to return -1 on error.
Why do you think you need it? Are you sure you have (more than) 4GB of contiguous memory?
You can take a look at the devel mailing list archives - this question is discussed there now and then. -
Why does QT use signed int for indexing an QList or other form of listed object?
QList<double> list; int index = 0; list[index] = 1.05;Arrays always start at Index 0, therefore I can't see any reason, why signed int is used.
The same applies for the return value of member functions like:list.size();The list can't be smaller than 0.
Is there any logical reason of taking signed values?
I have to convert them everywhere, because I use always unsigned values for things which can't handle negative numbers.Thanks for your answer
AlexAnother example:
IDs ofQButtonGroupstart at-2and decrease for every new button added to this group (default behavior).
-1is to auto-assign an ID. User-defined IDs should start at 0 (increasing).https://doc.qt.io/qt-5/qbuttongroup.html#addButton
So there are some cases where the sign matters.
(In addition to the-1which is returned e.g. as error code) -
Hi
Even if the other already explained it...
Think of it as a role. The role of being an index type.
We need sometimes to flag the index as invalid.
And since none ever uses negative indexes, using signed can be used for that.