Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129398

QButtonGroup::addButton() doesn't guarantee negative ids (as promised in docs)

XMLWordPrintable

    • All
    • 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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            chehrlic Christian Ehrlicher
            rbrinley RIchard Brinley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes