[Interest] Qml bindings with javascript library functions in them

Josh Faust jfaust at suitabletech.com
Thu Jun 13 21:42:00 CEST 2013

On Thu, Jun 13, 2013 at 11:41 AM, Alan Alpert <416365416c at gmail.com> wrote:

> Bindings do not update when a purely JS variable changes, it can only
> respond to changes in QML properties. You could bind to something like
>  stateObject.value, and still be able to use
> JS.setValue(stateObject.value + 1) if you wanted. But without going
> through C++ though you couldn't make stateObject.value read-only to
> everything but the setValue function.

Ah, I had forgotten about the distinction between properties and JS
variables. That gave me an idea though, and it looks like it works. I can
pass a QML object into the javascript, and use a property from it:

var _GenerationObject;
var _LastGeneration;
var _Value;
function setGenerationObject(obj)
  _generationObject = obj;

function getValue()
  // Force re-evaluation if _GenerationObject.generation changes
  if (_GenerationObject.generation != _LastGeneration)
    _LastGeneration = _GenerationObject.generation;

  return _Value;

function setValue(val)
  _Value = val;
  ++ _GenerationObject.generation;

Now the only trick is getting that value set before anything else
constructs, but that should be solveable.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130613/5b48a1c4/attachment.html>

More information about the Interest mailing list