01-10-2013 12:18 PM
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:
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
Solved! Go to Solution.
01-10-2013 01:06 PM
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.
01-11-2013 01:56 AM
Hi I try your suggestion, and it works
Many thanks
the key is using QSignalMap
04-11-2013 02:55 AM