[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] pyqtSlot and garbage collector
From:       marcos hipe <marcos91_3 () hotmail ! com>
Date:       2018-04-05 16:20:39
Message-ID: CAJ2kuhnGAikD+dqdePXAaYUA1UYNf2uBMyCR-8U6WvZ98hFOhw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello list!
I'm a little new here and with qt and pyqt, so i don't know what i'm doing
wrong

I searched the problem and found this link [0] with the same problem (from
2014) and with no solution

The problem is that i need to return a list of QObject in a Slot written in
Python to a QML, and when the list arrives to the QML it is a list of
undefined elements. The guess is that the garbage collector delete the
objects from the list before they arrive to the QML.

In [1] I make some test with a minimum example. In the main1 example, the
Slot return a list with two elements of a type that inherit from QObject
and have a simple property of a QString type, and in the output the
console.log print the list with two null objects.
In the main2 examples I change the return type of the Slot to a
QQmlListProperty, and the result is similar, but now the elements are
undefined.
In the main3 example I change the Slot in main2 to a pyqtProperty, and
change the call in the qml to suit that change and the list arrives
perfectly.
In the main4 i take the main1 example, but i convert the list in a instance
variable, so the garbage collector will not remove the elements in the
list, and the list arrives perfectly to the QML.

Is there some good way to solve this? I am doing something wrong?

Thank to read me!!

[0] http://python.6.x6.nabble.com/QML-garbage-collects-the-
model-td5064672.html
[1] https://gist.github.com/marcoshipe/81473609c0927bea0a17828de29cc2a9

[Attachment #5 (text/html)]

<div dir="ltr">Hello list!<br>I&#39;m a little new here and with qt and pyqt, so i \
don&#39;t know what i&#39;m doing wrong<br><br>I searched the problem and found this \
link [0] with the same problem (from 2014) and with no solution<br><br>The  problem \
is that i need to return a list of QObject in a Slot written in  Python to a QML, and \
when the list arrives to the QML it is a list of  undefined elements. The guess is \
that the garbage collector delete the  objects from the list before they arrive to \
the QML.<br><br>In [1] I  make some test with a minimum example. In the main1 \
example, the Slot  return a list with two elements of a type that inherit from \
QObject and  have a simple property of a QString type, and in the output the 
console.log print the list with two null objects.<br>In the main2 
examples I change the return type of the Slot to a QQmlListProperty, and
 the result is similar, but now the elements are undefined.<br>In the 
main3 example I change the Slot in main2 to a pyqtProperty, and change 
the call in the qml to suit that change and the list arrives perfectly.<br>In
 the main4 i take the main1 example, but i convert the list in a 
instance variable, so the garbage collector will not remove the elements
 in the list, and the list arrives perfectly to the QML.<br><br>Is there some good \
way to solve this? I am doing something wrong?<br><br>Thank to read \
me!!<br><div><div><div><div><div><div><br>[0] <a \
href="http://python.6.x6.nabble.com/QML-garbage-collects-the-model-td5064672.html" \
target="_blank">http://python.6.x6.nabble.com/<wbr>QML-garbage-collects-the-<wbr>model-td5064672.html</a><br>[1] \
<a href="https://gist.github.com/marcoshipe/81473609c0927bea0a17828de29cc2a9" \
target="_blank">https://gist.github.com/<wbr>marcoshipe/<wbr>81473609c0927bea0a17828de29cc2<wbr>a9</a></div></div></div></div></div></div><br></div>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic