QFLAGS : signed value is out of range for enum constant
-
@jsulm said in QFLAGS : signed value is out of range for enum constant:
xxxxxundefine
"xxxxxundefine" is also in the gVersions[], "gVersions[i].verNum != xxxxxundefine" will become false.
@MNGL said in QFLAGS : signed value is out of range for enum constant:
will become false
Well, if you are sure.
Else your app will crash with out of bounds exception. It is always a good idea to check the index for being in range. -
Unfortunately, I'm the guy who gonna maintain this project, the guy who design this did not expect the enum value will be out of range in less than 40 items.
@MNGL said in QFLAGS : signed value is out of range for enum constant:
did not expect the enum value will be out of range in less than 40 items
Your enum is a bit-flags enum. It does not hold sequential values (1, 2, 3, 4, ...), it holds sequential bits (1, 2, 4, 8, ...). So if you only give it 32-bits it will hold... up to 32 values. 40 items is not going to fit into it!
-
@MNGL Did you try what @KroMignon suggested?
-
@MNGL Did you try what @KroMignon suggested?
-
@jsulm Yes, I have. The QFlag class only works with int or unsinged int. https://doc.qt.io/qt-5/qflags.html.
Let'd assume we can use qint64 it just provides extra 32 items and will be used up soon in my case.
-
@MNGL Well, QBitArray and QFlag are two different things. You can't use QBitArray in code which expects QFlag.
In below post, BitArray is mentioned as alternative solution.
https://stackoverflow.com/questions/1060760/what-to-do-when-bit-mask-flags-enum-gets-too-largeI guess I have to get ride of following QFlag code and rewrite the whole thing.
if(Versions.testFlag(xxxxx920P4) )
-
@jsulm Yes, I have. The QFlag class only works with int or unsinged int. https://doc.qt.io/qt-5/qflags.html.
Let'd assume we can use qint64 it just provides extra 32 items and will be used up soon in my case.
@MNGL said in QFLAGS : signed value is out of range for enum constant:
Let'd assume we can use qint64 it just provides extra 32 items and will be used up soon in my case.
Just out of curiosity, it is not easier to change the "nature" of the enum and use plain values and not bit field?
Do you really need a bit field?It maybe easier to replace the bitfield enum with and plain value enum and use
QList
/QVector
on situation where you need to handle multiple values.Just my 2 cts.
-
typedef enum { Undefined = 0x00000000, H1 = 0x00000001, H2 = 0x00000002, H3 = 0x00000004, } Hardware; Q_DECLARE_FLAGS(Hardwares, Hardware) typedef struct { Version verNum ; Hardwares supportedHW ; } Settings ; const Settings gSettings[] = { { xxxxx400 , H1|H2|H3 }, { xxxxx401 , H1|H3 }, } ;
Now the "Hardwares" type is to store combinations of Hardware values. Due to the range limit, I want to change "supportedHW" to a different data structure. I tired following type:
QList<Hardware> supportedHW; //Got compiling errors:error C2552: 'supportedHW' : non-aggregates cannot be initialized with initializer list Hardware supportedHW[4] ; //pass compile, but not easy to use as QList and QFlags
Any suggestions? Thanks.
-
typedef enum { Undefined = 0x00000000, H1 = 0x00000001, H2 = 0x00000002, H3 = 0x00000004, } Hardware; Q_DECLARE_FLAGS(Hardwares, Hardware) typedef struct { Version verNum ; Hardwares supportedHW ; } Settings ; const Settings gSettings[] = { { xxxxx400 , H1|H2|H3 }, { xxxxx401 , H1|H3 }, } ;
Now the "Hardwares" type is to store combinations of Hardware values. Due to the range limit, I want to change "supportedHW" to a different data structure. I tired following type:
QList<Hardware> supportedHW; //Got compiling errors:error C2552: 'supportedHW' : non-aggregates cannot be initialized with initializer list Hardware supportedHW[4] ; //pass compile, but not easy to use as QList and QFlags
Any suggestions? Thanks.
@MNGL @KroMignon asked you whether your enum really has to contain bitfields: means 2^x values (0001, 0010, 0100, ...).
If this is not required then use just normal numbers, then your range is what an int provides and is for sure enough.