[Interest] Python staticmethod slot

Jérôme Godbout godboutj at amotus.ca
Wed Feb 5 20:56:06 CET 2020


Hi,
The init did not changed anything, here is the minimal replicate. I will open a bug if I did not made any obvious error there.

Thanks,
Jerome

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Cristián Maureira-Fredes
Sent: February 5, 2020 11:28 AM
To: interest at qt-project.org
Subject: Re: [Interest] Python staticmethod slot



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
--
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.py
Type: application/octet-stream
Size: 1169 bytes
Desc: main.py
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200205/33446604/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.qml
Type: application/octet-stream
Size: 551 bytes
Desc: main.qml
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200205/33446604/attachment-0001.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: requirements.txt
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200205/33446604/attachment.txt>


More information about the Interest mailing list