[PyQt] Exposing complex Qt objects as javascript objects
Ori Avtalion
ori at avtalion.name
Sat Jun 20 18:30:51 BST 2009
On 05/01/2009 05:33 PM, Phil Thompson wrote:
> On Thu, 23 Apr 2009 02:31:39 +0200, Henning Schröder
> <henning.schroeder at gmail.com> wrote:
>> On Tue, Apr 21, 2009 at 2:15 AM, Ori Avtalion<ori at avtalion.name> wrote:
>>> Hi,
>>>
>>> I'm trying to create a Qt object that will be exposed to javascript.
>>> I want that javascript object to be complex: It has nested objects
>>> inside it, and has arrays with other objects in them.
>>>
>>> I'm not sure how to define the properties for the top object that I
>>> expose. pyqtProperty doesn't accept "QVariant". (It returns the error
>>> "TypeError: type 'QVariant' is not supported as a property type")
>> Dynamic properties via setProperty use variants but I think it does
>> not work correctly for objects and widgets. It seems that the type is
>> not set to QMetaType::QObjectStar or QMetaType::QWidgetStar in the
>> constructor. At least QtScript does not recognize the variant as a
>> object or widget (see app property in attached example - the C++
>> equivalent would work this way).
>
> I think this is fixed in tonight's snapshot.
>
> If there is anything else that you don't think works properly then please
> let me know.
>
Actually, with version 4.5.1-snapshot-20090614 and sip 4.8.1 perhaps
there's a regression.
This method, when called from javascript, will return an empty string
instead of a javascript object.
It used to return a javascript object in 4.4.4
@pyqtSignature("fun()", result="QVariant")
def fun(self):
return QVariant({"one":1,
"arr":[1,2,{"three":3}],
"obj":{"foo":"bar"}
})
-Ori
More information about the PyQt
mailing list