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

Passing QVariants from QML to C++ causes them to have corrupted contents.

    XMLWordPrintable

Details

    Description

      Since QML doesn't support getting the value out of custom enumerations in signals, I tried to circumvent it by making a conversion function that would take in a QVariant containing the enumeration and convert them into integers. Let's assume the signal being as "void foo(EnumContainer::CustomEnumType result);" where CustomEnumType is contained within a QObject-derived class (hereafter referred as EnumContainer), it has been registered with Q_ENUMS and the container class has been registered for QML using qmlRegisterUncreatableType. When you catch this signal in QML, result is of type QVariant(EnumContainer::CustomEnumType), and it is impossible to compare this to any of the enumeration values. Now, if you try to pass this result to a C++ function having a signature of "Q_INVOKABLE int convertEnum(QVariant result);", the parameter result will contain the correct type (result.canConvert<EnumContainer::CustomEnumType>() is true), but its actual contents are random garbage.

      This is quite fatal since you can't really work around QML not recognizing custom enumerations as signal parameters currently without extensive hacks in design.

      Attachments

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

        Activity

          People

            aakenned Aaron Kennedy
            laitaan Antti Laitala
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes