[Interest] Python staticmethod slot

Cristián Maureira-Fredes Cristian.Maureira-Fredes at qt.io
Wed Feb 5 17:27:58 CET 2020



On 2/5/20 4:29 PM, Jérôme Godbout wrote:
> __________________
> Python code:
> __________________
> import math
> from PySide2.QtCore import QObject
> from PySide2.QtGui import QVector3D
> 
> class PointHelper(QObject):
>      @staticmethod
>      @Slot(QVector3D, result=bool)
>      def pose_position_is_nan(pose: QVector3D) -> bool:
>          """This does not work"""
>          return math.isnan(pose.x()) or math.isnan(pose.y())
> 
>      @Slot(QVector3D, result=bool)
>      def pose_position_is_nan2(self, pose: QVector3D) -> bool:
>          """This does work"""
>          return math.isnan(pose.x()) or math.isnan(pose.y())
> 
> ...
> qmlRegisterType(PointHelper,  "Toto", 1, 0, 'PointHelper')
> 
> ______________
> Qml
> ______________
> import Toto 1.0
> 
> PointHelper
> {
>          id: pointHelper_
>          Component.onCompleted:
>          {
>               pointHelper_.pose_position_is_nan2(Qt.vector3d(0,0,0)) // this does work
>               pointHelper_.pose_position_is_nan(Qt.vector3d(0,0,0)) // this does not work, console log: MyFile.qml:63: TypeError: Property 'pose_position_is_nan' of object PointHelper(0x1988c36ba10) is not a function
>               PointHelper.pose_position_is_nan(Qt.vector3d(0,0,0)) // this does not work, console log: MyFile.qml:64: TypeError: Property 'pose_position_is_nan' of object [object Object] is not a function
>          }
> }
> 
> Maybe I'm missing something?! If you want actual minimal running example I can provide it.
> 
> Thanks,
> Jerome


Hello,

AFAIK when you use qmlRegisterType, you should have a constructor
that call the inherit constructor, and when using setContextProperty,
you are allowed to not call the constructor.

So I'd say you should add a:

def __init__(self, parent=None):
     QObject.__init__(self, parent)

for that case.

I'd check the examples directory,
for some use cases of those two scenarios:
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/declarative

If still following the example mechanism,
I'd recommend you open a bug report with a minimal
reproducible example.

Cheers

-- 
Dr. Cristian Maureira-Fredes
R&D Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
--


More information about the Interest mailing list