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.

inside custom component

Native Development

Reply
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel
Accepted Solution

How to handle onTriggered many ActionItem created dynamically

Hi, I'm creating ActionItem dynamically using for (looping)

because data is from webservice

How to handle onTrigerred ?

 

so my code is like this :

 

for (int i = 0; i < aList.count(); i++)

{

Page* myPage = iRoot->findChild<Page*>("SpecificObject");
ActionItem* action = ActionItem::create().title(aList[i].name);

 

bool res = QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleAction())); // this I'm confused because I don't know which action being triggered
Q_ASSERT(res);
Q_UNUSED(res);

 

myPage->addAction(action, ActionBarPlacement::smileyvery-happy:efault);

}

 

void myClass::handleAction()

{

     aFunction(); // this function need parameter from aList, says aList[i].id

}

 

Is I must create SLOT handleAction() as much as actionItem being added

But I don't know how much action added because it is dynamic from server

 

 

Thanks

Please use plain text.
New Contributor
CatalystG
Posts: 2
Registered: ‎01-10-2013
My Device: 9900
My Carrier: Rogers

Re: How to handle onTriggered many ActionItem created dynamically

There are a few options:

 

Create a single slot, and connect all the signals to it. You can then call sender() in the slot to retreive the object that sent the signal and go from there. You could also use a QSignalMap which maps each signal to a value, and sends that value to a single slot. You can use QSignalMap::sender() to get the sender object also.

 

I used the QSignalMap successfully to do something similar for handling dynamically created dropdowns.

Please use plain text.
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: How to handle onTriggered many ActionItem created dynamically

Hi I try your suggestion, and it works

Many thanks

 

the key is using QSignalMap

Please use plain text.
Developer
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: How to handle onTriggered many ActionItem created dynamically

HI Kaz32,

I am also doing the same thing. But i am not able to implement QsingalMap. Can you please share some Code snippet.

Regards
Please use plain text.