Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Developer
greenback
Posts: 448
Registered: ‎10-17-2010
Accepted Solution

Detecting # of checkboxes selected

Let's say I want to detect the number of checkboxes selected in a Container, how would you do that exactly? Is there a way to get the properties of all child elements?

 

This has been stumping me all day. Thanks.

Please use plain text.
Contributor
chriske86
Posts: 43
Registered: ‎01-05-2013
My Carrier: Telenor Hungary

Re: Detecting # of checkboxes selected

There are many ways to detect the checked elements. Why don't you examine them in Javascript? If you know how much checkboxes you have in the Container, this is the best way I think. You need to add every checkbox an id, and when an event triggers (ex. button press, navigate forward) it, you check every checkboxes check property in Javascript, like:

 

onClicked {
 var checkedNum = 0;
 if (checkBox1.checked) checkedNum++;
 if (checkBox2.checked) checkedNum++;
 if (checkBox3.checked) checkedNum++;
 etc....
}

 But if you create checkboxes dynamically, you can get the whole QML object list in C++ side.

In the projectName.cpp file is some auto-generated lines:

 

AbstractPane *root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
app->setScene(root);

 The root object contains the whole QML hierarchy. You can get it with this command:

QObjectList children = root->children();

 So, children is a list, and it contains QObject elements. They can be iterated via a simple for cycle. Every QObject knows it's class name, so with this snippet, you can examine, that the actual QObject is a CheckBox or not.

for (int i = 0; i < children.count(); i++)
{	
  if (children.at(i)->metaObject()->className() == "CheckBox")
  {
    //do something
  }
}

 I hope it helps.

 

cheers,

chriske

--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Please use plain text.
Developer
greenback
Posts: 448
Registered: ‎10-17-2010

Re: Detecting # of checkboxes selected

Please use plain text.