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. No QML error when property missing from Q_GADGET
Qt 6.11 is out! See what's new in the release blog

No QML error when property missing from Q_GADGET

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 56 Views
  • 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.
  • B Offline
    B Offline
    Bob64
    wrote last edited by
    #1

    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.isCopyEnabled check because the other entry is added and the popup is shown. The behaviour is as if isCopyEnabled is 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.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote last edited by
      #2

      gadget.nonExistentProperty will evaluate to undefined so that's not a runtime error or warning.

      I believe qmllint would flag this though.

      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