dynamically load the Options in a drop-down list in C++

Hey guys,.

I'm trying to dynamically load items Option in a drop-down list by using C++.  I have a function in my class of WorkManager file that does the trick:

QStringList WorkManager::getListOfItems() {
    int i = 0;
    QStringList taskNames;  // used for debugging mainly, so i can print the list out to debug
    QList  myObjects = m_model->toListOfObjects();
    DropDown * dpList = bb::cascades::Application::instance()->scene()->findChild("scriptListDropDown");
    if (dpList != 0 ) {
        dpList->setSelectedOption(0);
        dpList->removeAll();
        for (i = 0; i < myObjects.size(); i++) {
            Task * myTask = (Task *) myObjects[i];
            taskNames.append(myTask->taskName());
            dpList->add(Option::create().text(myTask->taskName()).value(myTask->command()));
//          delete myTask;  // do I need to delete the task object?
        }
//      qDebug() << "WorkManager::getLIstOfItems(), ---> list of tasks is : " << taskNames;
        return taskNames;
    } else  {
        qDebug() << "WorkManager::getListOfItems(), ---> dpList was 0";
        return taskNames;  // empty list
    }
}

I also found this thread:http://supportforums.blackberry.com/t5/Native-Development/Adding-options-to-a-DropDown-from-c/m-p/21... that helped me get the filled drop-down list when the application starts.

However, I need to re - fill list from time to time, when the list (a GroupDataModel) changes.  calling the function above a second time anywhere in my application appears to hang the application immediately.

I think / thought it might have something to do with the slot for the onSelectedValueChanged, but I can't understand it.

It seems down right when I do dpList-> removeAll().

I also can't seem to find the right place to call this function to an object of type in my class.  I think it's because the drop-down list is not ready yet as the dpList * is always 0 unless what I call after the line:

app->setScene(root);

in the applicationui.cpp file.  Calling it works on start-up, but trying to update the list later (by removeAll() and recreate) causes the app crashing.

is there a better way to do it?  .. and make it safer?  I can't understand how to do this.

Thank you!

J

First, drop the:

dpList->setSelectedOption(0);

Not only if it is not necessary, but it will explode your application if the function is called when there is already no options in the menu dropdown.

Also, do NOT delete the task, because it is still owned by the datamodel. I also see that you use type casting C, which just blindly accepts your cast, even if it's a mistake. Instead, if you know for sure what kind it will be this way instead:

Task* myTask = static_cast(myObjects[i]);

If you are not sure if the type you are casting the is the type you need, use the dynamic_cast instead:

Task* myTask = dynamic_cast(myObjects[i]);

The advantage of this more static_cast , is that if you try to perform a type cast is not compatible, then myTask will be set to NULL.

Alternatively, Qt offers a replacement for dynamic_cast which works on platforms where is not regular C++ casts.

Task* myTask = qobject_cast(myObjects[i]);

It is functionally equivalent to dynamic_cast, but as I said, it works on all platforms that Qt exists, whereas dynamic_cast cannot.

Once you did get back to us.

oddboy wrote:

Hey guys,.

I'm trying to dynamically load items Option in a drop-down list by using C++.  I have a function in my class of WorkManager file that does the trick:

QStringList WorkManager::getListOfItems() {
    int i = 0;
    QStringList taskNames;  // used for debugging mainly, so i can print the list out to debug
    QList  myObjects = m_model->toListOfObjects();
    DropDown * dpList = bb::cascades::Application::instance()->scene()->findChild("scriptListDropDown");
    if (dpList != 0 ) {
        dpList->setSelectedOption(0);
        dpList->removeAll();
        for (i = 0; i < myObjects.size(); i++) {
            Task * myTask = (Task *) myObjects[i];
            taskNames.append(myTask->taskName());
            dpList->add(Option::create().text(myTask->taskName()).value(myTask->command()));
//          delete myTask;  // do I need to delete the task object?
        }
//      qDebug() << "WorkManager::getLIstOfItems(), ---> list of tasks is : " << taskNames;
        return taskNames;
    } else  {
        qDebug() << "WorkManager::getListOfItems(), ---> dpList was 0";
        return taskNames;  // empty list
    }
}

I also found this thread:http://supportforums.blackberry.com/t5/Native-Development/Adding-options-to-a-DropDown-from-c/m-p/21... that helped me get the filled drop-down list when the application starts.

However, I need to re - fill list from time to time, when the list (a GroupDataModel) changes.  calling the function above a second time anywhere in my application appears to hang the application immediately.

I think / thought it might have something to do with the slot for the onSelectedValueChanged, but I can't understand it.

It seems down right when I do dpList-> removeAll().

I also can't seem to find the right place to call this function to an object of type in my class.  I think it's because the drop-down list is not ready yet as the dpList * is always 0 unless what I call after the line:

app->setScene(root);

in the applicationui.cpp file.  Calling it works on start-up, but trying to update the list later (by removeAll() and recreate) causes the app crashing.

is there a better way to do it?  .. and make it safer?  I can't understand how to do this.

Thank you!

J

Tags: BlackBerry Developers

Similar Questions

  • If statement to change the items in a drop-down list

    Is there a way to change the options in a drop-down list in a script (without data binding)? So I have a drop down list and depending on what the user selects the second drop-down list will have different options. These elements can be specified by an if statement in the preOpen the second dropdown list event? The form will be filled out offline, so I don't want to put a link of data binding.

    Thank you!

    Hello

    There are at least two ways, as shown in http://forums.adobe.com/message/4321707#4321707.  Basically clearItems/addItem if pre Reader 9.0 or setItems supported if you use Reader 9.0 or later.

    Bruce

  • Populate drop-down list with the results of several drop-down lists

    Hi, I am creating a form where the results of two drop-down lists then would fill another drop-down list. I'm not new to javascript, but I'm new to using it in Acrobat, so while I found some answers to this: Drop-down list fill in multiple fields of text. I don't know where to implement this, if it is still the right thing, I'm looking for pipes for

    Oh and I use Acrobat Pro DC. Any help would be much appreciated!

    OK, you can create a function at the level of the document that is called in the Validate event of each of the two first drop down menus, something like:

    Function in JavaScript to the document level

    function updateDropdown() {}

    Get references to the drop-down menus of entry

    var F1 = getField ("DropdownList1");

    var F2 = getField ("DropdownList2");

    Refer to the output drop-down list

    F3 var = getField ("DropdownList3");

    Get the values of input field, as strings

    var s1 = event.target = f1? Event.value: f1.valueAsString;

    var s2 = event.target = f2? Event.value: f2.valueAsString;

    Fill the drop-down list of output with the elements, or deselect it if either input dropdown is 'empty' (single topic area)

    If (s1 = "" |) s2 === " ") {

    F3.clearItems ();

    } else {}

    F3.setItems (["", s1, s2]);

    }

    }

    In the two first downs Validate event, call this function like this:

    updateDropdown();

    You can of course name the function you want. More information about the properties and the methods used in the code are available in the Acrobat JavaScript documentation.

  • Download the news of a drop-down list for a field of text box

    Its that simple! That's all I need to know! The code to add to the information in a drop-down list (_cb) to a text field. I need to know wear put on the script IE in the action on the _cb layer. Your all!

    on the timeline that contains your combobox with instance name _cb that you can use:

  • Where is the past, bookmark button that displays all THE bookmarks as a drop-down list?

    I had to reinstall my OS, and now I don't see the big 'Favorites' button, I got to the right of the search box Google with Firefox.
    It is with the value 'Icons' of icons.
    I use to be able to click on "Favorites" and they appear in a drop-down list, like 'latest news' power works.
    I can click the Favorites (with the star on this subject), who comes here to open a sidebar - not a menu drop-down which disappears when I clicked it.

    I loaded Windows 7 and took some quick screenshots for you:
    http://tinyurl.com/3c7ouvs

    Also note that it only shows the bookmarks menu button if you use the Firefox menu button and not the classic menu bar, because it would be quite redundant to have a button and the bookmarks at the top menu which does exactly the same thing.

    Look at what you have in the toolbar and what is in the window customize (you may need to scroll down). If you have one in the toolbar then the other is probably in the window customize somewhere. If you have a lot of addons installed there may be many buttons to look through.

    If you have problems you can just click on the 'Restore Default Set' button in the Customize dialog box to restore the default values that will also involve of the bookmarks that you want to switch all your toolbars. If you had any other customizations to your toolbars and then change them back again.

  • Modification of the properties-type def drop-down list box

    I have a group of 32 cases of a def type. The def type contains several different types of control. What I have to do is to change the properties of the list box for each of the type defs. Normally, I would create an array of references to change the properties for each of the type defs, but when I try this I can not access the properties of string [] for combo box selections. The only way I found to fix it is to create a reference for each individual drop-down list box item. It is labour, since I'll have 32 elements. Is there a way to beeter to do this? The first screenshot shows the issui I'll have, not being able to change the properties of specific elements within each of the def type at runtime through a control [] array. The second screenshot shows the only solution I've found so far, which is not very practical.

    You will need to set up (for a more specific class) control to a type of combo box for the particular control [] index that has the combobox control if you want to access the drop-down list.

    You can also access the combobox in a cluster based directly, rigth click on the control reference and a link to the element cluster directly.

    The last option is to make the strictt of typdef will fill all instances with the channel list [] given that it is a strict property.

    the approach is based on the weather, you plan on changing the list during execution.

  • Add options from a drop-down list of c ++

    In my C++ files, I have a QMap to data that I want to add a drop-down menu that I have in QML.

    I can't find examples of how to add options to a menu already existing but.  Here's what I have in my file QML right now:

    DropDown {
                        id: account
                        title : "Account"
                        enabled : true
                    }
    

    It seems it should be a fairly easy process to get the id of the drop-down list and enter the data of my inside QMap.

    Any help with this would be greatly appreciated!

    Oh, I didn't see that you do not know how to connect the logic of C++ to the UI QML, the ID of the component QML is not enough, you must set objectName: property 'dropDown' too.

    You can reach any CPP QML object like this:

    This excerpt comes from YourProjectName.cpp
    create the active document of the main.qml scene
    Set parent document created to ensure that there is overall
    application lifetime

    QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);

    Create the root for the UI object
    AbstractPane * root = qml->() createRootObject;
    game created the root like a scene object
    App-> setScene (root);

    and here's the findChild method
    Drop-down list * dpList = root-> findChild ("combo");

    After this line, dpList will point to the controller of the user interface.

  • How to increase the length of a drop down list?

    Hello

    I hope you do well!

    I have a page of the ADF that was created automatically to a human task.

    I have several drop-down lists (SelectOneChoice) in the form, but they are sized according to the data in it.

    It seems weird with different sizes, if I want to make the size of the set of fixed length. How can I do?

    I tried changing the 'size', 'width' options, but nothing works. Even try a few forums. You please help me in this regard.

    Thanks in advance.

    Concerning

    RaviKiran

    Hello

    I have it!

    Width: 175px in ContentStyle the fact. Thank you.

  • Help select the value from a drop-down list box

    Hello

    I develop a script (in JavaScript) which will allow a user to select an export PDF presets (that are loaded in a drop-down list) and then export the InDesign file to PDF, by using the selected PDF preset.

    I have the combo fill properly and I am also able to export to PDF correctly, however I have a problem setting the preset has been selected by the user. Here are some of my code fragments:

    Drop-down list:

    with(borderPanels.add()) {

         pdfDD = dropdowns.add();

         sl = new Array();

         for (i = 0; i < app.pdfExportPresets.length; i++)

         sl.push(app.pdfExportPresets[i].name);

         pdfDD.stringList = sl;
         pdfDD.selectedIndex = 0;

    }

     

    ...

     

    myPreset = pdfDD.selectedIndex;

    In PDF format:

        // Open, Export, & Close
        for (i = myFileAmount; i >= 0; i--) {
            app.open(File(myFolderContents[i]));

            createHyperlinks();

            app.activeDocument.exportFile(
            ExportFormat.pdfType, File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"), false, myPreset);
            app.activeDocument.close(SaveOptions.no);
        }

    During the passage of myPreset, it is defined as 6 (the index from the drop-down list).  How can I set myPreset that the real value of what has been chosen?

    Thank you!

    In view of your code, you probably need something like:

    myPreset = app.pdfExportPresets.itemByName (pdfDD.stringList [pdfDD.selectedIndex]);

    @+

    Marc

  • Make visible or invisible drop according to the value of another drop-down list. Help!

    Hello

    I need to create the following form... I want to choose at the beginning of the shape between 3 options (imagine: 'Opt1', 'Opt2' and 'Opt3'). And after that, I would like to make visible 10 different lists. I mean, if I choose 'Opt1', 10 drop-down lists related to 'Opt1' will become visible (the drop-down list together, including the text of the title and the clean drop-down list). Otherwise, if I choose 'Opt2', 10 drop-down lists related to 'Opt2' will become visible and the same 'Opt3 '.

    This problem, which seems to be very easy to resolve, it is impossible for me. I have read hundreds of forums and manuals, but I can't find the solution. I tried with several thousands of events, but I can't do the form works as I want... So, please, can someone help me?

    Thank you very much.

    Hello

    Here is an example. The script is located in the event of changing the drop-down list. The easiest way is to group your drop-down menus in subforms, then simply script for the visibility of three subforms, instead of 30 drop-down menus.

    The script focuses on the choice of the user and changes the visibility by using a switch statement. One if exposed to the exit event would work as well.

    switch (xfa.event.newText)
    {
         case 'Option 1':
              option1.presence = "visible";
              option2.presence = "hidden";
              option3.presence = "hidden";
              break; 
    
         case 'Option 2':
              option1.presence = "hidden";
              option2.presence = "visible";
              option3.presence = "hidden";
              break; 
    
         case 'Option 3':
              option1.presence = "hidden";
              option2.presence = "hidden";
              option3.presence = "visible";
              break; 
    
         default:
              option1.presence = "hidden";
              option2.presence = "hidden";
              option3.presence = "hidden";
              break;
    }
    

    Note that all three subforms are hidden in Design view. The drop-down list choice makes the appropriate subform visible.

    In design mode, you can select a subform in the view of the hierarchy and in the object/field tab change its visibility to visible, if you want to work on it in the design.

    Hope that helps,

    Niall

  • Make a field of text/hide according to the results of a drop-down list box

    Hello

    I wonder if someone could help me with this. I want to show/hide some text boxes in my form according to the choice made by the person filling in. For example, there is a dropdown list containing a selection of numbers 1-4. If 1 was selected, the text boxes below 1 would be visible and obligatory, if the 2 have been chosen, 2 text boxes below would be visible and required etc...

    I'm new to FormCalc (only started using it this morning), so simple a possible explanation would be fantastic.

    Thanks for reading!

    Of course, you can have javascript and formcalc in the form. Not only the two in the same field, same event; D

    Okey, let's try some things:

    (1) check if the "binding" from the drop-down list is the same as the values that you choose. In the script you are referring to the bound values.

    (2) other names for the Textfields would be better, because it is more difficult to refer to "Textfield1 [1]" then to for example: 'New '. I was just to lazy to give them names. (If it's on another page or subform, you refer to the fields correctly: as MyForm.FirstSubform.FirstTextfield... this name lies in the specific script field.)

    (3) check your script once more... want to make invisible mandatory fields?

    (4) check if your form is dynamic. (If it isn't you will not see the changes...)

    You should probably do it in small steps, such as:

    (1) first of all, you refer to areas such as:

    This.rawValue = Firstfield.rawValue;

    If the changed value fields got you its name and to be sure that the event you put is the right one.

    (2) try the different parts of the script and look at how it works. Problems can be more easily found and then

  • drop-down lists on the forms don't drop-down list

    I use Firefox 3.6.16 on Mandriva 2010.2 and for the last two months, the drop-down lists don't dropdown. I thought a patch would come out to fix it or it would be one of my modules cause. There was an update recently and it has not fixed. Today, I've disabled all addons and restarted, but still it does not allow me to make a choice with the mouse.

    There are many similar problems with FF4, but none of the solutions appear to be relevant.

    Anyone got any suggestions?

    < edit > I just disabled all the plugins too but still the same. What I noticed at the time, is that there seem to be two versions of Flash installed, but only the first shows under tools modules Plugins

    There is no need to create a new thread. You can edit your first post and change the title, if you want to change it or I can do it if you post a better title.

    Problems with a menu drop-down does not not can be caused by an extension.

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions of the origin of the problem (switch to the DEFAULT theme: Tools > Modules > appearance/themes).

    See:

    If this does not work in mode without failure, then disable all extensions and then try to find out who is the cause by allowing both the problem reappears.

    • Choose "Disable all add-ons" on issues to troubleshoot Firefox in Safe Mode to set window to disable all extensions.
    • Close and restart Firefox after each change through "file > exit ' (Mac: ' Firefox > leave";) Linux: "file > exit ')
  • How to change the items in a drop-down list box that is part of an array of clusters

    Hello

    In the attached vi, I have an array of clusters and each cluster contains two drop-down list boxes. How can I edit the items in the drop-down list box 1 for all elements in the array? (All elements of list box 1 has the same elements.)

    By way of illustration, I have also included the case of trivila, for example, edit the items in a separate drop-down list box that is is not part of an array of clusters (combo box 3). Please notify. Thank you.

    Peter

    Right click on the drop-down list box and select Create-> Node-> String() property. Place it on the block diagram. Change to write (right click) and then feed him an array of strings.

  • Customize the Format of text, drop-down lists

    Hey all,.

    I have problems of customization of the top botton label of a water drop down. I can customize cell converters labels, but the top label is not affected and is always Times New Roman... Any ideas what I'm missing here?

    Here is a screenshot:

    Here's my CellRenderer customized for the drop down:

    public class CustomDropDownCellRenderer extends DropDownCellRenderer
        {
            public function CustomDropDownCellRenderer()
            {
                super();
            }
    
            override protected function init():void{
    
                var format:TextFormat=new TextFormat();
                format.font="font_helveticaNeue";
                format.size=16;
                format.color=0x000000;
    
                super.init();
    
                setTextFormatForState(format, SkinStates.DISABLED);
                setTextFormatForState(format, SkinStates.UP);
                setTextFormatForState(format, SkinStates.DOWN);
                setTextFormatForState(format, SkinStates.SELECTED);
                setTextFormatForState(format, SkinStates.DISABLED_SELECTED);
                this.label.label_txt.embedFonts=true;
            }
        }
    

    Here's where I put the drop down skin:

    brushDropDown=new DropDown();           brushDropDown.setListSkin(CustomDropDownCellRenderer);
    brushDropDown.setButtonSkin(CustomDropDownButtonSkin);          brushDropDown.addEventListener(Event.SELECT, brushDropDownEventHandler);
    brushDropDown.dataProvider=brushShapes;
    

    I thought I might have to customize the DropDownButtonSkin, but this class does not have a label...

    Any help would be appreciated.

    Hey,.

    I've done some research more and similarly to another thread involving the selector, the own only cut the way to do it is by creating a class sup from the drop-down list. However, this one is kind of weird. Once again, with assistance from flash builder, I could see the protected class drop-down list properties and the objective here is the purpose of __button. now the weird part is that its type is a DropDownButton. they took that as an accessible API since the new update. but I managed to make some changes anyway.

    so the solution, create a void called CustomDropDown class that extends the class from the drop-down list. After that, in the constuctor, use the this.__button.getTextFormatForState () method to manipulate the textformat of the button. Here is an example:

    ListTests.as:

    package{   import flash.display.Sprite;  import flash.display.StageAlign;  import flash.display.StageScaleMode;
    
      import qnx.ui.data.DataProvider;  import qnx.ui.listClasses.DropDown;   import qnx.ui.listClasses.List;
    
      [SWF(width="1024",height="600",backgroundColor="#E8E8E8",frameRate="30")] public class ListTests extends Sprite {     private var myList:CustomDropDown;       private var myDataProvider:DataProvider;      private var myArray:Array;
    
          public function ListTests()       {         super();
    
              // support autoOrients            stage.align = StageAlign.TOP_LEFT;            stage.scaleMode = StageScaleMode.NO_SCALE;
    
              myList = new CustomDropDown();           myArray = new Array();
    
              myArray.push({label: "Thomas Luddington"});           myArray.push({label: "Master Maruyn"});           myArray.push({label: "Master Gardyner"});         myArray.push({label: "Captain Vaughan"});         myArray.push({label: "Master Kendall"});          myArray.push({label: "Master Prideox"});          myArray.push({label: "Robert Holecroft"});            myArray.push({label: "Rise Courtenay"});          myArray.push({label: "Master Hugh Rogers"});          myArray.push({label: "Thomas Foxe"});         myArray.push({label: "Edward Nugen"});            myArray.push({label: "Darby Glande"});            myArray.push({label: "Edward Kelle"});            myArray.push({label: "Iohn Gostigo"});            myArray.push({label: "Erasmus Clefs"});           myArray.push({label: "Edward Ketcheman"});            myArray.push({label: "Iohn Linsey"});         myArray.push({label: "Thomas Rottenbury"});           myArray.push({label: "Roger Deane"});         myArray.push({label: "Iohn Harris"});
    
              myDataProvider = new DataProvider(myArray);
    
              myList.dataProvider = myDataProvider;
    
              myList.setPosition(10,10);            myList.width = 300;
    
              addChild(myList);
    
          } }}
    

    CustomDropDown.as:

    package{   import qnx.ui.listClasses.DropDown;   import qnx.ui.skins.SkinStates;
    
      public class CustomDropDown extends DropDown {     public function CustomDropDown()      {         super();
    
              this.__button.getTextFormatForState(SkinStates.UP).font = "Comic Sans MS";            this.__button.getTextFormatForState(SkinStates.SELECTED).font = "Comic Sans MS";          this.__button.getTextFormatForState(SkinStates.DOWN).font = "Comic Sans MS";          this.__button.getTextFormatForState(SkinStates.DOWN_SELECTED).font = "Comic Sans MS";                  } }}
    

    And Yes, clearly I'm a fan of Comic-who isn't?

    Yet once, it is going to work identical to the drop-down list but instead allows you to set your own font. in fact, you can create a new method which is what I did in the above code, so you can change the font on the fly without having to make five different subclasses just to change the textformat! hope that helps. Good luck!

  • By selecting an option in a drop-down list displays a hidden text box and checkbox

    Being fairly new to the creation of pdf form I would be grateful for some assistance.

    I'm looking to have a number of choices in a drop-down list (dropdown1) show a hidden textbox (textbox1) and the box (checkbox1)

    The selections that would show are:

    iPad only

    Or

    Laptop and iPad

    I'm sure it's rather easy.

    Thanks in advance

    You can use this code as the custom for the drop-down list field validation script:

    var f1 = this.getField("textbox1");
    var f2 = this.getField("checkbox1");
    
    if (event.value=="iPad Only" || event.value=="Laptop and iPad") {
        f1.display = display.visible;
        f2.display = display.visible;
    } else {
        f1.display = display.hidden;
        f2.display = display.hidden;
    }
    

Maybe you are looking for