Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Double negation for 'enabled-prop' of an Action - why?
Forum Updated to NodeBB v4.3 + New Features

Double negation for 'enabled-prop' of an Action - why?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 572 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rengel
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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

      (Z(:^

      1 Reply Last reply
      2
      • R Offline
        R Offline
        rengel
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved