[Interest] Will Qt6 end this enum issue? (or even 5.15?)

Jason H jhihn at gmx.com
Thu Mar 19 15:04:22 CET 2020

The enums in QML are expressed as ints when printed. console.log(camera.position) => 1
I work around this as:
property var positions: ["Unspecified", "BackFace", "FrontFace"]
onPositionChanged: console.log(positions[position]);

Or worse yet:
property var flashModes: {
	  1: "FlashAuto",
	  2: "FlashOff",
	  4: "FlashOn",
	  8: "FlashRedEyeReduction",
	 16: "FlashFill",
	 32: "FlashTorch",
	 64: "FlashVideoLight",
	128: "FlashSlowSyncFrontCurtain",
	256: "FlashSlowSyncRearCurtain",
	512: "FlashManual"

It seems that enums should be class with a value and label
console.log(camera.position.label) => "BackFace"
console.log(camera.position.value) => 1

Though I can understand if this might not be the preferred way. It's just I spend so much time doing this. I'm open to anything really
console.log(Camera.positionEnum(camera.position).label) == "BackFace"
console.log(Camera.positionEnum(camera.position).value) == 1
console.log(Qt.enum(camera.position).label) == "BackFace"
console.log(Qt.enum(camera.position).value) == 1

Also, in Qt I occasionally encounter enums that are not registered and cannot be used in QML without registering them myself. Will Qt registering all enums for use in QML be standard for Qt 6?

More information about the Interest mailing list