[PyQt] Conversion from QML
Phil Thompson
phil at riverbankcomputing.com
Thu Jan 8 07:23:35 GMT 2015
On 08/01/2015 5:36 am, B. B. wrote:
>> Didn't you always have to call toString() etc. to get the actual
>> values,
>> even with Qt v5.3?
> >
>>
>> If so then implementing the mapping protocol should allow you to write
>> code that would work with both v5.3 and v5.4 without needing to be
>> changed.
>>
>> Phil
>>
>
>
> No, It was not neccesary, because there was no QJSValue in what the
> function returned.
I was misled by your app.py example calling property() in section 2.
> With the combination :
> Qt :
> 5.3
>
> PyQt :
> PyQt-gpl-5.4-snapshot-
> 15b37c22d541 ( from around 17 of november )
>
> Sip:
> sip-4.16.5-snapshot-c005a6d2e53e ( around 17 of november )
>
> All values returned were already "python values":
> ( from the example, earlier in this thread ):
>
>
> The return value with combination Qt5.3 , PyQt, sip from 17/11 )
>
> {'texts': [<PyQt5.QtCore.QObject object at 0x7f1d6c11fc18>], 'good':
> 'yes'}
>
>
>
> The return value with Qt5.4 , PyQt, sip from about 25/12, is that
> QJSValue:
>
> <PyQt5.QtQml.QJSValue object at 0x7f2563921898>
>
> This is the QJSValue type, one have to pack out, to get the "python
> one"
> like the one above...
>
>
>
> Because the return value earlier contained "pure python", like str,
> dict
> and list, along with PyQt5 objects, like QObjects,
> I thought the PyQt5 earlier did a processing, prepareing the result.
> But
> that was somehow lost in progress since november.
>
> This was a pure guess, I have really not looked into changes from
> qt-5.3 to
> qt-5.4, or in any PyQt sources....
>
>
> Because of you question, I see a little hope for the smooth easier old
> way
> of returning :-)..
> I will try to run the example a crossed sources, ( New PyQt5 with
> qt-5.3 ,
> or PyQt5 from november with qt-5.4 - if that is possible ). Just to
> verify...
I could do the automatic conversion of bool, QDateTime, QObject etc. and
leave it as a QJSValue if no obvious conversion could be done. However
there must have been a reason for the change in Qt v5.4 - maybe because
the isError(), isNull(), isUndefined() states were being lost by Qt v5.3
automatically converting to a QVariant.
I don't have enough personal experience with using QML to know what the
right thing to do is, so feedback needed.
Phil
More information about the PyQt
mailing list