-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.5.6, 6.7.3, 6.8.0 RC
-
None
-
-
772d374ce (dev), 85af81746 (6.8), ed5025590 (tqtc/lts-6.5)
The documentation for QButtonGroup::addButton() states:
If id is -1, an id will be assigned to the button. Automatically assigned ids are guaranteed to be negative, starting with -2. If you are assigning your own ids, use positive values to avoid conflicts.
However, this is evidently not true from reading the implementation (qtbase/src/widgets/widgets/qbuttongroup.cpp, starting at line 206):
if (id == -1) { const QHash<QAbstractButton*, int>::const_iterator it = std::min_element(d->mapping.cbegin(), d->mapping.cend()); if (it == d->mapping.cend()) d->mapping[button] = -2; else d->mapping[button] = *it - 1; }
If there are already items in the map, this will choose an id one less than the minimum, which does not guarantee a negative number. For instance, if a user first adds a single item with id == 2, then adds another with id == -1, the second will be automatically assigned an id of 1, not -2, as the documentation states.