[Interest] Checking QML property against null

Alex Montgomery apmontgomery at gmail.com
Tue Jul 15 21:49:13 CEST 2014


Hello,

Sorry for what seems like an incredibly simple question, but how do I check
a QML property against null without triggering the Qt warning, "TypeError:
Cannot read property of null"?

I have a type that has a custom property declared like this:
property MyType myProp: null

My program then will set myProp to an appropriate value for MyType where
appropriate. However, sometimes that property is left as null or set back
to null, and in QML I have code like this:

onMyPropChanged: { if (myProp) doSomething(); }

Unfortunately that if statement always triggers the TypeError warning when
myProp is intentionally set to null. I just want to be able to check
against null without Qt spitting warnings at me. I've tried:
"if (myProp)"
"if (myProp != null)"
"if (myProp !== null)"
"if (myProp != undefined)"

Any ideas?

Thanks much,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140715/3e4b1e12/attachment.html>


More information about the Interest mailing list