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

QVariant converts int to enum even when there is no enumerator matching the value

    XMLWordPrintable

Details

    Description

      QVariant has a "magic" ability to convert from int and QString towards an enumeration registered via Q_ENUM. When using a QString, there is a check in place to verify that the string is the name of an enumerator:

      QVariant v("CoarseTimerXXX"); // not an enumerator
      bool ok = v.convert(qMetaTypeId(Qt::TimerType)); // false
      

      The same check is not there for integers:

      QVariant v(123456); // not a valid value
      bool ok = v.convert(qMetaTypeId(Qt::TimerType)); // TRUE (!)
      

      I'd argue that the second should fail as well. Yes, in C++ it's legitimate and well-defined behavior store that integer value into the enumeration; but we're dealing with QVariant and a conversion, and I'd expect it to be strictier.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes