QML: To access variables defined outside of a list item to in a list component

Consider the following QML:

import bb.cascades 1.0


{Page}
content: {container
  {Label
  ID: topLabel
      text: «One»
      textStyle.size: 100.0
      textStyle.color: Color.Blue
  }

    Button {}
      text: 'change two.
      onClicked: {}
      topLabel.text = "Two"
    }
    }


    {To ListView
      objectName: "testList".

      listItemComponents:]
      {ListItemComponent}
        type:
        Button {}
          text: "change to three.
          onClicked: {}
            topLabel.text = "Three"
          }
        }
      }
    ]

maxHeight: 300.0
}
}
}

The pages defines three controls: a label, a button, and a listview. In turn, each listview item also contains a button.

By clicking on the button below the label successfully changes the text of the label through this code:

onClicked: {}
topLabel.text = "Two"
}

However, the execution of a similar code from the button in the listview control fails with this error:

Test.QML:28: ReferenceError: can't find variable: topLabel

Apparently, the variables defined outside the listview are not directly visible since in listview items.

Y at - it available to access syntax?

Thank you

Jamie

OK, we have identified a work around that should solve your problem, as suspected, she was reported linked so a redefinition is necessary.

At the high level of the Page of the page, add the following line so that the label is accessible.

{Page}
ID: topPage
    
onCreationCompleted: {Qt.topLabel = topLabel ;}
        
Then, in the button definition, you can reference the Qt.topLabel in the list.

listItemComponents:]
{ListItemComponent}
type: 'point '.
Button {}
text: "change to three.
onClicked: {}
Qt.topLabel.text = "Three";
}
}
}
]

Hope that solves your problem. Of course, it worked on my system.

Graham

Tags: BlackBerry Developers

Similar Questions

  • Access to the information in the list component

    I've attached a screenshot of information Ineed to 'to '. I'm still relatively new to Flex and I have a total disconnect what code use so I tried all kinds of properties and functions. Now I'm really confused. I want the user to be able to remove one of the restaurants, and then send the list to themselves. The listComponent ID is favoritesList. The dataProvider comes from drag - move to a datagrid control. The dataProvider of the DataGrid is a collection arrayCollection with the id restaruatnsAC.

    Thank you

    This trick is to create a second, empty, collection ArrayCollection that is bound to the data in the list drop-enabled.  When you want to do something for the items in this list, you just work with this 2nd ArrayCollection collection.  Heres a code:

    "http://www.adobe.com/2006/MXML" xmlns:ns1 ="*" >

    Import mx.collections.ArrayCollection;

    [Bindable]

    private var ac:ArrayCollection = new ArrayCollection([)

    {restaurant: 'Restaurant 1'},

    {restaurant: 'Restaurant 2'},

    {restaurant: "Restaurant 3"},

    {restaurant: 'Restaurant 4'}

    ]);

    [Bindable]
    private var ac2:ArrayCollection = new ArrayCollection();

    private function removeSelected (): void {}
    AC2.removeItemAt (chosenList.SelectedIndex);
    }

    ]]>


       
           
       


       
           
       

    I hope this helps.

    Joe

  • How Textfield text on another page qml property access

    Hello

    I started 10 BB development recently and need help. I searched this forum but could not find some information exactly related to my problem (unlike only), or I missed something from basically. My main.qml, I want to access the text property of the textfield of the InputControl.qml to be used as a parameter in my SQLQuery (attached object). I tried to use the fieldname method alias property, but it does not work. I can't feature outside. Here is my code:

    hand. QML

    import bb.cascades 1.4
    import bb.cascades.datamanager 1.2
    import bb.system 1.0
    import bb.data 1.0
    
    Page {
    
        id: root 
    
        titleBar: UIControls {
        }
    
        //! [0]
       content: Container {
    
            leftPadding: ui.du(2)
            rightPadding: ui.du(2)
            topPadding: ui.du(2)
            bottomPadding: ui.du(2)
    
            InputControl {
            }
    
            // The ListView that's used to display the artist data
            //! [1]
            ListView {
                id: myListView
    
                //property variant dq: defaultDataQuery
                // Associate the list view with the data model that's defined in the
                // attachedObjects list
                layout: StackListLayout {
                    headerMode: ListHeaderMode.Sticky
                }
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 1.0
                }
                horizontalAlignment: HorizontalAlignment.Fill
                verticalAlignment: VerticalAlignment.Fill
    
                listItemComponents: [
    
                    ListItemComponent {
                        type:  "item"
    
                        Container {
                            Label {
                                text: ListItemData.Japanisch
                                layoutProperties: StackLayoutProperties {
    
                                }
                                topMargin: 5.0
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Bold
                                    color: Color.create("#7a184a")
                                }
    
                            }
                            Label {
                                text: ListItemData.Lesung
                                textFit.maxFontSizeValue: 9.0
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Normal
                                    color: Color.create("#ff1818e9")
                                }
    
                            }
                            Label {
                                text: ListItemData.Deutsch
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Normal
                                }
    
                                multiline: true
                                textFit.maxFontSizeValue: 8.0
                            }
                            Divider {}
                        }// Container
                    }
                    // Use a standard list item to display the data in the model
                ]    
    
            } // end of ListView
    
        }//![1]
    
        attachedObjects: [
            //! [2]
            // One of the default provided DataModel's
    
            GroupDataModel {
                id: dataModel
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource
    
                // Load the data from an SQL database, based on a specific query
                source: "WadokuJT.db"
                //query: "select Japanisch, Deutsch, Lesung from WadokuJT where Deutsch like '%Wasser%'"
                query: "select Japanisch, Deutsch, Lesung from WadokuJT where Deutsch like '%" + stext + "%'";
    
                onDataLoaded: {
                    // After the data is loaded, insert it into the data model
                    dataModel.insertList(data);
    
                }
                type: DataSourceType.Sql
            } // end of DataSource      
    
        ]//! [2]  
    
        actions: [
            //! [8]
            ActionItem {
                title: qsTr("Search")
                imageSource: "asset:///images/ic_search.png"
                ActionBar.placement: ActionBarPlacement.Signature
                onTriggered: {
                    myListView.dataModel = null
                    dataSource.load()
                    //myListView.dq = defaultDataQuery
                    myListView.dataModel = dataModel 
    
                }
            },
    
            ActionItem {
                title: qsTr("Settings")
                imageSource: "asset:///images/ic_settings.png"
                onTriggered: {
    
                }
            },
    
            ActionItem {
                title: qsTr("Help")
                imageSource: "asset:///images/ic_help.png"
                onTriggered: {
    
                }
            }                           
    
        ]//![8]
    
    } // end of Page
    

    And here is my InputControl.qml

    import bb.cascades 1.4
    
     Container {
         property alias stext: txtSearchText.text
    
        Label {
            id: lblSearchText
            text: "Searchtext\r\n"
    
        }
    
        TextField {
            id: txtSearchText
            layoutProperties: FlowListLayoutProperties {
    
            }
            hintText: "Enter Searchtext"
        }
    }
    

    Any help is greatly appreciated. Thank you.

    Give InputControl an id (in main.qml), for example someId.

    Access the variable an alias like someId.stext

  • Call a variable from outside a function

    Hey everybody!

    I am so confused. I hope that someone can help me here! I try to call the variable named "time' go outside a function. '"

    Here is my code:

    var myXML:XML = new XML();

    var XML_URL:String = 'youtube - time.xml";

    var myXMLURL:URLRequest = new URLRequest (XML_URL);

    var myLoader:URLLoader = new URLLoader (myXMLURL);

    myLoader.addEventListener (Event.COMPLETE, xmlLoaded);

    var time;

    function xmlLoaded(event:Event):void

    {

    time = XML (myLoader.data);

    }

    trace (Time);

    Here's what my XML looks like:

    10 < time > < / time >

    Whenever I run the trace (time); outside the service - I get an "undefined" message in the output window.

    How can I access the variable " " time "outside my service so I can assign to another variable like this: "

    var VIDEOS_SECONDS = time;

    Thank you very much for any help!

    Timothy

    Functions are called, the variables are accessible.

    First thing you need to do is to check that xmlLoaded is actually called. Copy your trace statement to test. If you never actually call the .load method on your URLLoader object, as suggested by Colin, nothing will never load.

    Second, if your code snippet above is literally everything from an image and run correctly, then most likely your trace statement executes before the XML loading data are completed. URLLoader runs asynchronously, which means that your main code stream do NOT stop and wait until she finishes.

  • Peopleimages property possibly access not defined through a reference with static type class.

    Hello

    I have a custom MXML component called SeeElement.mxml, within this file I defined a VBOX as shown

    SeeElement.mxml

    < mx:VBox id = 'personimages' >
    < mx:Label id = "viewname" / >
    < / mx:VBox >

    Now inside another ActionScript file, I try to make visible to false, as shown:
    SeeElement. peopleimages.visible = false;

    I am thie error

    Peopleimages property possibly access not defined through a reference with static type class.

    Please help me solve this problem.

    Thank you.

    inside your "a few other sctionscript the file' you need a reference to the SeeElement object

    var seeElement:SeeElement = new SeeElement();

    Then you can seeElement.personImages.visible = false;

    SeeElement (with a capital S) refers to the class SeeElement and personImages is not a class member variable its an instance member variable

  • Sharing Variables defined by the user through projects

    Hello

    I wonder if it is possible to share Variables defined by the user between projects. What I have in mind, is that I would like to have my user defined Variables configured in a central location and then insert them into my projects as variables bound so that they update automatically when I change their values. For example, I define a variable named ProductVersion , that has the value 9. Then I insert this variable in all my projects as a bound variable. After 2 months the product version changes was 10, so I change the value of the variable at 10 to the place where it is stored and it is automatically updated in all projects. Is it possible somehow? I'm new to RoboHelp and I find no answer. I tried the solution for a while using the product on the Internet without success. I even contacted Adobe Support and they redirect me to this forum I used help and manual before and how they deal with user variables was quite simple.

    Hello

    Unfortunately RoboHelp does not offer a way to let this, at least, is not directly.

    However, I think I found a way to get there, the variables are stored in a file named rhvariable.apj. So what you could do is to add this file as a file of luggage to each of your projects that will share variables.

    Now, you would create a shared location, but also a new category in your resource manager. This will create a common location to store the file apj.

    Add the file of baggage to the location. Repeat for all the projects that share variables.

    Now, when the variable is changed in any of the project participants, it should be to update the shared location and you can achieve the goal.

    Note, however, that although you'll get what you want, it will be always open each of the participating projects, synchronize the APJ file and generate the output in order to to refresh all. No way, I am aware of escape that.

    Cheers, Rick

  • Can I get several variables defined by the user in a slide?

    I used the variables defined by the user in the past to collect information on the results of the quiz, as well as for the certificate of quiz.  I would like to re - use variables in a few areas.  in my project, a slide invites you the user name (variable, I created), second will prompt you for the user ID (variable, I created).  I would like a third screen that reads 'Confirm your previous entries', and I want to show him the two variables.  I see only one.  Is it possible to get them both to display?

    I also want to re - use both in the quiz at the end certificate.  If I change the certificate in Flash widget, will be the two variable display?

    This quiz brings to me by email (we have no LMS).

    Any suggestions?

    Cyndi Nagel

    Hi again

    You reduce the screen shot before you download? You are right. It's barely legible.

    If the variables are inserted into more than a legend, double have you checked the timing? Maybe something is pause the slide before one of the legends has a chance to appear.

    See you soon... Rick

    Useful and practical links

  • Access a drop-down list component created in fom runtime C++

    Hello everyone.

    I included a file "Settings.qml" as a ComponentDefinition in my file "main.qml" as follows:

    *******************************
    main.qml
    *******************************
    
    Page {
        id: page
    
        //App menu
        Menu.definition: MenuDefinition {
            settingsAction: SettingsActionItem {
                title: "Settings"
                imageSource: "asset:///icons/ic_settings.png"
                onTriggered: {
                    var settings = settingsSheet.createObject(_cam);
                    settings.open();
                }
            }
        }
    
        //Main container
        Container {        Camera {            id: cameraQML            objectName: "cameraQML"        }    }
    
        //Attached objects
        attachedObjects: [
            //*****this is the component definition****
            ComponentDefinition {
                id: settingsSheet
                source: "Settings.qml"
            }
        ]
    }
    

    Then, in the "Settings.qml" file, I have something like that.

    On the crack of onCreationCompleted I call you access of wich C++ function to the cameraQML component and gets the available resolution values and add them to the drop down list component.

    ***********************Settings.qml***********************
    
    Sheet {
        id: settingsSheet
        objectName: "settingsSheet"
        peekEnabled: true
        content: Page {        Container {            DropDown {
                    title: "Capture Resolution"
                    objectName: "resolution"
    
                    options: [
                        Option {
                            text: "16:9"
                            value: 16/9
                        }
                    ]
    
                    onCreationCompleted: {
                        _cam.loadResolutionValues();
                    }
    
                    onSelectedValueChanged: {
                        //_cam.selectResolution(selectedValue);
                    }
                }
            }    }}
    

    The PROBLEM comes when I try to access the menu item drop down because, even if I get error when you call the function findChild(), I do when I try to add Options by calling the add() function:

    ******************applicationui.cpp******************
    
    AbstractPane* root;Camera* cameraQML;DropDown* resolutionsDD;
    
    void AppliactionUI::ApplicationUI() {    //code...    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);    qml->setContextProperty("_cam", this);    root = qml->createRootObject();    cameraQML = root->findChild("camera");    //code...}void ApplicationUI::loadResolutionValues() {
        QVariantList reslist = camaraQML->supportedCaptureResolutions(CameraMode::Photo);
                    //**I don't get error by calling this function
            resolutionsDD = root->findChild("resolution");
    
            //**The app do crashes when calling any of these three functions
        //resolutionsDD->setTitle("Choose an option");        //resolutionsDD->removeAll();
        //resolutionsDD->remove(resolutionsDD->at(0));    for (int i = 0; i < reslist.count(); i++) {
            qDebug()<<"QVatiant value:"<add(Option::create().text(res.width()+"x"+res.height()).value(reslist[i]));
        }
    }
    

    I thought it was a problem with the type of value, I was put in the service. value() when you create an option, but then I realized that, while trying to change the title from the drop-down list, or delete i ' ts options that the application crashed also.

    This makes me think that the problem is that I'm not a correct reference for component drop-down menu QML due to the fact that this drop-down list does not exist when the application starts and is created until the user opens the Settings.qml file. Also, I think that this is a problem with all that stuff parent and child, but of course, it's just a feeling.

    I'd really appreciate your help on this type of problem. I'm not experienced enough to know what is the right way to get a reference of work to the drop down list component in question in a situation like this

    Thank you very much in advance!

    P.D. I'm sorry, I know that my English is not very good. Hope you do not misunderstand

    Hello
    Very probably findChild returns NULL and a NULL pointer dereference causes the crash. I remember there was problems with findChild during the use of the leaves.

    Try from the drop-down list directly to the function as an argument:

    (1) in applicationui.cpp:

    After:
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    
    Add:
        // This is needed for passing DropDown in function parameters from QML to C++
        qmlRegisterType("bb.cascades", 1, 0, "DropDown");
    

    (2) modify the function declaration for:

    Q_INVOKABLE void loadResolutionValues(bb::cascades::DropDown *dropDown);
    

    (3) in QML:

    DropDown {
      id: dropDown
      ...
      onCreationCompleted: {
         _cam.loadResolutionValues(dropDown)
    
         // _cam.loadResolutionValues(this) // maybe this will also work, but I haven't checked
    
      }
    }
    
  • Not able to access the parent instance variable in outside of the methods in child

    Hello

    I don't get why I am not able to access the instance variable parent class apart from the example of the child class methods.
    class Parent
    {
         int a;
    }
    
    class Child extends Parent
    {
         a = 1; // Here i am getting a compilation error that Syntax error on token "a", VariableDeclaratorId expected after this token
         
         void someMethod()
         {
              a = 1;  // Here i am not getting any compilation error while accessing parent class variable
         }
    }
    Can someone let me know the exact reason for this, and what about the talks of error?

    Thank you
    Uday

    Published by: Udaya Shankara Gandhi on June 13, 2012 03:30

    You can only put assignments or expressions inside the methods, of the builders or the initializors class, or when you declare a variable.
    It has nothing to the child which stretches from Parent.

    class Parent {
        int a = 1;
    
        { a = 1; }
    
        public Parent() {
            a = 1;
        }
    
       public void method() {
           a = 1;
       }
    }
    
  • Flash Wrapper and access user-defined variables

    I'm working on creating a Flash AS3 wrapper to combine several files cpativate.  I am able to retrieve system variables, but I'm not able to recover the user-defined variables.  I have a variable that is defined by the user in my Captivate called passedScore, in my Flash script, I have the following...

    var mcLesson1:MovieClip;

    btnHit.addEventListener (MouseEvent.CLICK, test);

    var vLoader:Loader = new Loader();

    vLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, swfLoaded);

    vLoader.load (new URLRequest ("untitled1.swf"));

    function swfLoaded(e:Event):void {}

    mcLesson1 = MovieClip (vLoader.contentLoaderInfo.content);

    vLoader.contentLoaderInfo.removeEventListener (Event.COMPLETE, swfLoaded);

    addChild (mcLesson1);

    }

    function test(event:MouseEvent):void

    {

    feedback1. Text = mcLesson1.cpInfoCourseName;

    feedback2. Text = mcLesson1.m_VarHandle.passedScore;

    }

    retroaction1 correctly displays the name of the course, however, for feedback2 it errors saying a term are indefinite (referring to m_VarHandle)

    try to use mcLesson1.cpEIGetValue ('m_VarHandle.passedScore');

  • to access the variables defined in the Document class

    I can't evaluate the values established in my document class.

    My document class: ZoneViewer.as:

    SerializableAttribute public class ZoneViewer extends Sprite {}
    private var zone_area_alpha_low:Number is. 2;
    }

    This code exists on a frame in a movieclip in my main script:

    This.zone_shape.Alpha = zone_area_alpha_low;


    How to access the valeur.2 which is declared in my class: document ZoneViewer.as? "zone_area_alpha_low" does not work.

    Solution to the problem of access to a variable value (zone_area_alpha_low) from actionscript code framework in a movieclip.

    FYI... my project file structure:

    Project_Folder/MyApplication.fla
    Project_Folder/MyApplication.swf
    Project_Folder/classes/ZoneViewer.as
    --------------------
    Document class: classes. ZoneViewer

    {classes package

    import flash.display.MovieClip;

    SerializableAttribute public class ZoneViewer extends MovieClip {}

    public static var zone_area_alpha_low:Number =. 1;
    }
    }
    --------------------
    This code exists on the first frame of my movieclip in my .fla file.

    import classes. ZoneViewer;< i="" was="" missing="" this="" import="" statement="" within="" my="">
    This.zone_shape.Alpha = ZoneViewer.zone_area_alpha_low;< this="" finally="" is="" referenced="">

    Kudos to ntbdy for the light. Is there better ways to do this?

  • Access Variables JavaScript Iscript

    Hi all

    I just want to confirm one thing, can I access Javascript variables (which are defined in the definition of HTML) in IScript. If Yes please tell me how I can do.

    Thank you

    I can also inject the table number PeopleCode in JavaScript array?

    NO.

    Is there no workaround solution to do this?

    Yes. Probably the simplest way is to use the method of the PeopleCode Array.join . Your PeopleCode will look like this:

    &numbers.join(",", "[", "]");
    

    This converts your table to a string. You will then pass this string as another link so your JavaScript will look like:

    var numbers = %Bind(:2);
    
  • To access the page defined by a dynamic action item

    I have a page element that is defined by a dynamic action. However, if I try to access this page anywhere else on the page element, it is null. Y at - it a specific method to dynamically reference the value of page elements, other than the usual & p2_page_item. reference. TIA.

    Hello!

    Where do you reference point? In another DA, process page?

    & NOM_ELEMENT. the syntax is only for the static text and it will be avoided in SQL and PL/SQL. It will get only value when the page is loaded.

    If you are referencing the element DA or JS, you can get its value with the function $v (for example $v('ITEM_NAME'). If you reference the process item, you can get its value with the standard bind variables syntax (: nom_element) or with the function v (for example v('ITEM_NAME'). If this process is inside the dynamic action, value of the item must be saved before session state.

    BR,
    Marko

  • Has no type constraint-access variables of loaded swf

    Hey,.

    I have a problem accessing a variable loaded from another swf. In fact, the variable is a class singeltone, which must be initialized. It has the structure presented in the last part of the message.

    The project has the following structure:
    -main.swf - this all the other swf files and holds their load.
    -assets.swf - contains common elements and initializes the SingleTone class
    -interface.swf - contains some elements of the interface and must use the SingleTone class
    -all SWFs three have access to a common class structure, where the SingleTone class is defined.

    The problem I have now, accesses the SingleTone class in the interface.swf file. If I try to send the SingleTone.singleTone.property of the class parameter I get "type coercion failed: cannot convert ClassName @..» to ClassName. If I try to access the SingleTone class directly in the interface.swf file, I get "cannot access a property or an a null object reference...". ». The two errors I have seem logical:
    -If I send a parameter, I send the reference to this object, but the interface.swf file does not have access to the field of assets.swf.
    -If I try to access the SingleTone class directly in the interface.swf file, I get error null because the class is not initialized on the interface.swf domain.

    Are there close to work? I know that a simple solution may be to initialize the variable in the area of the interface.swf, but what if there is a variable that can be instantiated in the assets.swf? I can access this variable to another swf, or if I can change the ApplicationDomain?

    I found the problem. In the main.swf file, when I loaded the other 2 files, I didn't specify the LoaderContext. So now, I changed the context loader so that all files will be responsible for their class definitions in the same field. Here is a small example from senocular and the link.

  • How to access variable double * (an array) of c. in TestStand

    Hello

    I'm trying to access an array of numbers, measured by the multipoint read DMM operation. The expected data is double [] (an array of measures as defined by "ividmm.dll"), but when "nidmm_32.dll" (NEITHER IVI driver) is used to perform the same operation, the data is returned as double * (from CVI/C code). Although double [] and double * would mean the same thing.

    The problem do face is the matrix defined by 'Locals.Reading' defined in good TestStand shims only when she used with 'ividmm.dll' and not 'nidmm_32.dll '.

    The DLL used and examples of sequence files are also attached. The name of the step where the error occurs is 'Reading Multipoint' with readingsArray parameter.

    Any help or suggestion to go to these two types of data types in TestStand would be greatly appreciated.

    Note: TestStand version: 4.0

    Thank you

    Matrat

    Note that the readingArray parameter is declared with the category of digital and position pass by reference when you use the function niDMM_ReadMultiPoint, but when you use the IviDmm_ReadMultiPoint function there class of array of numbers.

    I suspect that the function type information stored in nidmm_32.dll is incorrect for the niDMM_ReadMultiPoint function. To test this theory, manually change the type of the parameter array of numbers and see if it works.

Maybe you are looking for