[Interest] Using Qt Enums as QML object keys... Qt6?

Jason H jhihn at gmx.com
Fri Mar 6 18:26:42 CET 2020


First, sometimes I find that not all Qt enums are exported to QML.
Like the QProcess::ProcessState, IIRC. Are these bugs? Shouldn't all Qt enums in QObject recived classes be Q_ENUM()ed?

Next, QML's uage of these is normally an int, when I print these with console.log() they come out as 0,1,2,3, etc. However, I was going to [ab]use this and tried
var nameForState = {
QProcess.NotRunning: "QProcess::NotRunning",
QProcess.Starting: "QProcess::Starting",
QProcess.Running: "QProcess::Running",
}

But instead I have to provide an array:
var nameForState = [ "QProcess::NotRunning","QProcess::Starting","QProcess::Running"]
then index.
console.log("process state", index, nameForState[state]);
But this is a weaker binding and sometimes the table in the docs is not present, or if is present aren't ways in sorted order. Also QFlags are not possible to do this way.

I am hoping for Qt6, we can console.log() without this additional lookup? Or at least use the object-based lookup and not the array version?


More information about the Interest mailing list