PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 924 - Allow QScriptValue to be accessed via []
: Allow QScriptValue to be accessed via []
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtScript
: HEAD
: PC Linux
: P3 enhancement
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-07-10 12:28 EEST by Thomas Perl
Modified: 2011-07-22 22:12 EEST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Perl 2011-07-10 12:28:48 EEST
If I'm getting a QScriptValue from e.g. a JavaScript dictionary or array, it
would be good if I could use the [] operator on the QScriptValue to retrieve
data from this value, just like one would do in JavaScript, i.e.:

 from PySide.QtCore import *
 from PySide.QtScript import *

 app = QCoreApplication([])

 engine = QScriptEngine()
 value = engine.evaluate('x = {"a": 1, "b":2}')
 print value['a'] # should be equivalent to value.property('a').toVariant()

Due to the way the engine works, we could then also access array members via a
numeric index (which would be converted to a string for property access):

 value = engine.evaluate('x = ["x", "y", "z"]')
 print value[1] # should be equivalent to value.property('1').toVariant()

In case the property returned is not valid (.isValid() returns False), a
KeyError should be thrown if the key was a string, and an IndexError should be
thrown if the key was an integer.
Comment 1 Hugo Parente Lima 2011-07-11 20:49:44 EEST
Sounds nice to me.
Comment 2 Hugo Parente Lima 2011-07-18 20:16:54 EEST
Fixed in commit:

pyside/2fd0e8fcb81361fac0f06737d7c694d50372412e
Comment 3 renato filho 2011-07-22 22:12:52 EEST
release 1.0.5