No QML error when property missing from Q_GADGET
-
I have a Q_GADGET C++ object for a bunch of properties that I expose to QML. In a recent refactor I inadvertently removed the Q_PROPERTY specification for one of the properties I wanted to expose.
This led to some unusual behaviour in the UI as the property was used in some logic to determine whether to show a particular entry in a popup menu. Although I have fixed it by re-exposing the property, I am baffled that there was not more of a run-time failure from QML. The code is something like this:
... if (data.isCopyEnabled) // <<<< isCopyEnabled not exposed from gadget ... // add "Copy" entry to menu if (data.isDeleteEnabled) ... // add "Delete" entry to menu ... menu.open(); }I have things set up so that I see QML runtime warnings in my console, and I see nothing there when this executes. Also, it is clear that execution continues over the
data.isCopyEnabledcheck because the other entry is added and the popup is shown. The behaviour is as ifisCopyEnabledis false.Is this expected behaviour? I am sure I have seen more noisy behaviour of one type or another in the past when I have attempted to access an attribute that does not exist on a C++ object exposed to QML.
-
gadget.nonExistentPropertywill evaluate toundefinedso that's not a runtime error or warning.I believe qmllint would flag this though.