'How to handle macOS dock Quit action in QML app?

I have a simple ApplicationWindow that should prevent quitting by overriding onClosing signal. However, when the app is closed from macOS dock, the onClosing is not called. How to fix that?

import QtQuick 2.9
import QtQuick.Controls 1.4 as Controls1

Controls1.ApplicationWindow {
    id: root
    visible: true

    onClosing: close.accepted = false
}

Qt 5.15.2, macOS 10.14.6



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source