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

[Reg in Qt 6] setProperty() fails for QFlags types

    XMLWordPrintable

Details

    • 98e21f0979 (qt/qtbase/dev) 98e21f0979 (qt/tqtc-qtbase/dev) 729a326d85 (qt/qtbase/6.3) 729a326d85 (qt/tqtc-qtbase/6.3) 2932130a8e (qt/qtbase/6.4) 2932130a8e (qt/tqtc-qtbase/6.4) 2932130a8e (qt/tqtc-qtbase/6.4.0) b0ea59146e (qt/tqtc-qtbase/6.2)

    Description

      For example (Qt::textFormat is an enum while Qt::Alignment is a QFlags):

          const QVariant v1("RichText");
          const QVariant v2("AlignBottom");
          QLabel l;
          qDebug() << l.setProperty("textFormat", v1); // true in Qt 5 and 6
          qDebug() << l.setProperty("alignment", v2); // true in 5, FALSE in 6
      

      What it looks like to me is that setProperty() ends up in QMetaProperty::write(), and in Qt 5, it enters the block that calls key[s]ToValue(), which successfully decodes the string to enum values. But in Qt 6, that block is never entered at all, since it is behind this (changed) test:

      if (isEnumType() && !t.metaObject() && v.metaType().id() == QMetaType::QString)
      

      and the middle term fails - both the metatypes do in fact have a metaObject. But I don't know if that test is as it should be or not.

      Anyway, we next run into another Qt 6 issue/bug, in QVariant, which may or may not be related. Since, we did not enter the block above, the code instead tries to call QVariant::convert(). That succeeds for TextFormat but fails for Alignment - even though the QVariant claims to be able to convert a string in Qt 6:

          qDebug() << v1.canConvert<Qt::TextFormat>(); // true Qt 5 and 6
          qDebug() << v1.value<Qt::TextFormat>(); // Qt::RichText in 5 and 6
          qDebug() << v2.canConvert<Qt::Alignment>(); // false 5, TRUE in 6 ?
          qDebug() << v2.value<Qt::Alignment>(); // empty QFlags in 5 and 6
      

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              vgt Eirik Aavitsland
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: