Solved Double negation for 'enabled-prop' of an Action - why?
-
In the Qt Documentation for 'Action QML Type', the property 'enabled' has the value
enabled: (!!activeFocusItem && !!activeFocusItem["cut"])
context:
Action { id: cutAction text: "Cu&t" shortcut: StandardKey.Cut iconName: "edit-cut" enabled: (!!activeFocusItem && !!activeFocusItem["cut"]) onTriggered: activeFocusItem.cut() }
Why does the value use two double negations? Are they required? If so, why?
Is this just a JavaScrip 'trick' for a more elaborate expression?
If I remove these double negations, the code works as well. -
Yes this is a JavaScript thing. It will treat all false-like states as false (undefined, false, 0, null, etc.). More info https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript
-
Thanks! That helped. I'm using PyCharm with the QML plugin. This plugin flags (falsely) the double negation as a syntax error. I have posted this error on the QML Support webpage of JetBrains.