Are BitField Unions discouraged in Qt?



  • In the past outside of Qt I have done a lot of bit field work like this:

    @union GlyphBitFlags {
    uint32_t all;
    struct {
    uint32_t errors:1;
    uint32_t noarguments:1;
    uint32_t querymode:1;
    uint32_t editmode:1;
    uint32_t helpmode:1;
    uint32_t immediateArgValid:1;
    uint32_t bracketOpen:1;
    uint32_t bracketClose:1;
    };
    };@

    Qt seems tolerant of this. But its IDE isn't very helpful. For example:

    @GlyphBitFlags glyph;
    glyph.errors = false; @

    If I typed in creators IDE glyph., the pop up help doesn't display any suggestions for the bit field names. I wonder if this form of storing data is discouraged in Qt since it designed to be cross platform.

    If have looked at using QBitArray. Which is nice, except the bits are anonymous and I have to create a enum to get at them. This wouldn't be that big of a deal, except when I use Qt's debugger. The bits are even further removed because I see them presented in byte form. Wonder if there is anything else Qt offers to help create this kind of data structure?


  • Moderators

    Hi,

    Qt does that using the "QFlags class":http://qt-project.org/doc/qt-5/QFlags.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.