<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class="">I have a custom object property system that adds properties to QObject instances and am trying to expose those [dynamic] properties to qml.</div></div><div class=""><br class=""></div>Is it possible to add a qt property to a QObject instance, as opposed to adding it using pyqtProperty as a decorator in the class declaration?<div class=""><br class=""></div><div class=""><div class="">The PyQt5 docs say that you can use pyqtProperty in the same way as the python property() function apart from the decorator, but I haven’t had much success with this:</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(108, 108, 29); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">def</span><span style="font-variant-ligatures: no-common-ligatures; color: #dadada" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">test_property</span><span style="font-variant-ligatures: no-common-ligatures; color: #dadada" class="">():</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #2d961e" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">(QObject):</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">def</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #6c6c1d" class="">__init__</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">):</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">._mine = 12</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.mine = pyqtProperty(</span><span style="font-variant-ligatures: no-common-ligatures; color: #696795" class="">int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.get_mine, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.set_mine)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">def</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #6c6c1d" class="">get_mine</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">):</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">._mine</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">def</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #6c6c1d" class="">set_mine</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">, x):</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">._mine = x</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(242, 242, 242); background-color: rgba(0, 0, 0, 0.85098); min-height: 17px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c1651c" class="">a</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = A()</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(a.mine)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c200ff" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(a.mine())</span></div></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(218, 218, 218); background-color: rgba(0, 0, 0, 0.85098);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">turin:pkdiagram patrick$ python test.py</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><PyQt5.QtCore.pyqtProperty object at 0x114ea1840></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Traceback (most recent call last):</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "test.py", line 743, in <module></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    test_property()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  File "test.py", line 740, in test_property</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    print(a.mine())</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">TypeError: Required argument 'fget' (pos 1) not found</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(242, 242, 242);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">turin:pkdiagram patrick$ </span></div></span></div></body></html>