How to have QML interpret a property as null (instead of undefined)?
I'm trying to have registered object properties appear as their values, OR as null, in QML. The only way I've been able to get close to this "can also be null" behaviour is to define the property as type QVariant:
return QDateTime(self._my_date) # no PyQt autoconvert for datetime->QVariant
Unfortunately, the QVariant that ends up in QML with `return None` is being interpreted as `undefined` in QML/JS. I want it to be `null` in QML/JS.
I expect (but can't confirm yet) that a QVariant of type "QMetaType::Void" *might* get interpreted as `null` in JS, but am unable to create such a QVariant with PyQt. The first problem is that neither QMetaType.create or QMetaType.construct are available.
Even more interesting is that something (PyQt?) is actively preventing me from creating a Void instance...
Re: How to have QML interpret a property as null (instead of undefined)?
Is this a documented technique? If not, I would avoid it. Use only the documented way of doing this, and if none is documented, there is likely a reason that the feature is not available. In that case, find and understand the reason, and fix your design accordingly.