[Interest] Accessing a QML object, via constructed id in JavaScript

Filip Piechocki fpiechocki at gmail.com
Tue Apr 15 09:58:27 CEST 2014


Hi Eric,

What is the reason you can't use it like this:

if (english_weight1.checked)


but instead you are refering to the item by name? Maybe your mistake
is with the construction you are using?


BR,

Filip




On Tue, Apr 15, 2014 at 6:50 AM, Eric Feigenson <eric at feigenson.net> wrote:

> Hello all...
>
> I'm writing some JavaScript code inside QML.  What I'd like to do is be
> able to access an object via id where the id is in a JavaScript string.
>
> For example, given the QML:
>
>         CheckBox {
>
>             id: english_weight1
>
>             text: qsTr("2.5 lb")
>
>         }
>
>
> and the JavaScript fragment:
>
>         var idName = "english_weight1";
>
>         if (idName.checked)
>
>             // do something is the box is checked...
>
>
> But I want the idName in the "if" statement to refer to the *value* of
> the JavaScript variable "idName", in other words,
> "english_weight1.checked". I believe I could use eval:
>
>         if (eval(idname + ".checked")) ...
>
>
> but everything I've read says eval is to be avoided.
>
> If it helps or makes any difference, the CheckBox is in a Column with id
> myColumn.  I was thinking something like
> myColumn[idName] would do the trick, but I'm only guessing.
>
> I hope this is a clear enough description... please let me know if any
> more details are needed.
>
> Any thoughts?
>
> Thanks!
>
> -Eric
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140415/87cf54cd/attachment.html>


More information about the Interest mailing list