[PyQt] Conversion from QML

B. B. thebbzoo at gmail.com
Sat Jan 3 17:10:38 GMT 2015


Hey Phil,

The error had actually been easier explained making a short example from
the beginning...

Attatched is the sources for a very small program that demostrate what I
mean.
The introspection is done just by printing to the console.
I print out in 2 sections - the first "makes sence" with the new source,
the second makes sence with the old sources.

You will notice in the second - with the old sources - the result from the
"getStuff" function is python dicts and lists.

Which if a much cleaner interface than the QJSValues the getStuff returns
with the nevest sources.. :-)


My output is here:

This is the console output from the program executed on the newest sources:
Remark, the data is a QJSValue.... all is returning QJSValues...

------------- 8< ---------------

running section 1
print( data ) :
<PyQt5.QtQml.QJSValue object at 0x7f2563921898>
print( data.property( "good" ) ) :
<PyQt5.QtQml.QJSValue object at 0x7f2563921908>
print( data.property( "texts" ) ) :
<PyQt5.QtQml.QJSValue object at 0x7f2563921908>
-- finish running section 1 --

running section 2
print( data ) :
<PyQt5.QtQml.QJSValue object at 0x7f2563921898>
print( isinstance( data , dict ) ) :
False
print( data["good"] )
-- error running section 2 --
'QJSValue' object is not subscriptable

------------- >8 ---------------



Here on the "old" sources from november...
Remark, data is a python dict...

------------- 8< ---------------

running section 1
print( data ) :
{'texts': [<PyQt5.QtCore.QObject object at 0x7f1d6c11fc18>], 'good': 'yes'}
print( data.property( "good" ) ) :
-- error running section 1 --
'dict' object has no attribute 'property'

running section 2
print( data ) :
{'texts': [<PyQt5.QtCore.QObject object at 0x7f1d6c11fc18>], 'good': 'yes'}
print( isinstance( data , dict ) ) :
True
print( data["good"] )
yes
print( isinstance( data["texts"] , list ) )
True
print( data["texts"][0].property( "text" ) )
cute cute cute
-- finish running section 2 --

------------- >8 ---------------


If you need more information or tests, please let me know....

Best Regards,

Brian



On Fri, Jan 2, 2015 at 2:15 PM, Phil Thompson <phil at riverbankcomputing.com>
wrote:

> On 29/12/2014 9:14 pm, B. B. wrote:
>
>> Hello Phil,
>>
>> I just updated, to the newest versions available.
>>
>> Qt :
>>  5.3 -> 5.4
>>
>> PyQt :
>> PyQt-gpl-5.4-snapshot-15b37c22d541  ( from around 17 of november ) ->
>> PyQt-gpl-5.4
>>
>> Sip:
>> sip-4.16.5-snapshot-c005a6d2e53e ( around 17 of november ) ->
>> sip-4.16.6-snapshot-0e9e078d2d18
>>
>>
>> In python, I have access to a PyQt5.QtQuick.QQuickItem, got from qml
>> through a slot.
>>
>> On the QQuickItem object, I call javascript functions, definded in qml,
>> for
>> example like thisone:
>>
>> qml:
>> --------------------
>> 1
>> Item {
>>
>>         function thisone( ) {
>>             return { prefix : "goods" , items : [ idOfItemX, idOfItemY ] }
>>         }
>>
>> }
>> ---------------------
>>
>> I mean, I call in python, on the python QQuickItem. like :
>> myResult = myPythonQQuickItem.thisone().
>>
>> In the earlier version, the myResult was a python dict, and myResult[
>> "items" ] was a python list
>> containing PyQt5.QtQuick.QQuickItem objects
>>
>> In the newes version, I only get a myResult is a PyQt5.QtQml.QJSValue, and
>> one have to do the "marchalling" oneself.
>>
>>
>> Is this "lack of automatic marchalling to obvious python types" a change
>> that is going to stay, or is it just an regression in the newest sources
>> ????
>>
>>
>> using python3.4, the "problem" verified on linux and Mac...
>>
>
> Can you send me a short, complete example that demonstrates the problem.
>
> Phil
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150103/47775522/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: app.py
Type: text/x-python
Size: 1894 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150103/47775522/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: app.qml
Type: application/octet-stream
Size: 641 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150103/47775522/attachment.obj>


More information about the PyQt mailing list