Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++ Enum class exposed to QML is read with more bits than defined in Qt 5.15 as opposed to 5.12

C++ Enum class exposed to QML is read with more bits than defined in Qt 5.15 as opposed to 5.12

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 331 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devjb
    wrote on last edited by devjb
    #1

    I ran in some strange looking issue in our code today. We call a C++ class member from within QML, which returns an

    enum class SomeEnumeration : quint8 {MEMBER_0=0,MEMBER_1=1,MEMBER_2=2,MEMBER_3=3,MEMBER_4=4,MEMBER_5=5};.

    In Qt 5.12.7 the value displayed in a label for that enum is a value between 0 and 5.

    If I build the very same code with Qt 5.15.2, I get strange readings of 32512 to 32517

    From that bit pattern it was a rough guess then that qml might not take into account the underlying type of an enum but instead interprets it as being a signed 16 bit value. (0x7F00 to 0x7F05). It seems to simply ignore the length.

    This is very strange, given the fact that it doesn't do that for Qt 5.12.7.

    When I cange my underlying enum type to be a 16 bit long type, the QML engine reads the correct value.

    The only bug that I came over looking for the behaviour which might be related in some way was https://bugreports.qt.io/browse/QTBUG-71947

    However, the issue there seems to be not about the length of 8 or 16 bits not being respected.

    Any ideas how to not being forced to change all my 8 bit enums to 16 bit ones?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have the same issue if using qint8 as enum type ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        devjb
        wrote on last edited by
        #3

        No, the change from quint8 to qint8 has no effect.

        However, I could invesigate a bit more, but only to get more confused.

        The misbehaviour happens when I compile the project with MSVC2019. When I change the enum to be represented by a 16 bit type, it translates to the correct values.

        When I compile the Project using MSVC2017 and Qt 5.12.7, the enum also translates correctly.

        When I compile the project using MinGW, the enum, even when quint8-based gets also translated correctly.

        I then tried to reproduce the behaviour by assembling a minimal example. The project where the situation happens is a huge subdir project consisting of numerous dlls.

        In the minimal example I built exactly the same mechanisms into a very smallproject consisting of only one class and one qml page. The surprising thing is: I cannot reproduce the misbehaviour in that setup, neither using MSVC2019 nor MinGW.

        After that analysis, I tend to judge the microsoft compiler to be the root cause of the issue. Even when it is able to build a correctly working minimal project, in the real project only MSVC2019 is causing the issue.

        Therefore I will set the topic to solved, because it hardly is a framework bug, but more of a compiler issue that shows up under certain circumstances.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved