I want to create a QMenu that contains QAction objects that are checkable. Once an action is checked, it will fire and enable drawing of some 3D object. However, the number of 3D objects depends on what files to be loaded. Thus, this QMenu have dynamic number of QAction objects. Suppose we have 10 3D objects with names "1", "2", ... "10" and thus the QAction objects in the QMenu would be displayed as "1", "2", ... "10". When one of these are checked, 3D object of that name will be enabled to display.
Code to generate dynamic QAction objects:
QStringList labels = defaultScene->getLabels();
for(int i=0; i<labels.size(); i++){
QAction* labelAction = new QAction(labels[i], this);
labelAction->setToolTip("Trace Marker " + labels[i]);
labelAction->setStatusTip("Trace Marker " + labels[i]);
labelAction->setCheckable(true);
traceMenu->addAction(labelAction);
}
My question is, how do I connect these QAction objects? Specifically, I have an array of bool in defaultScene that will be toggled as the QAction are toggled. How am I to know which QAction is firing? The SIGNAL of QAction on toggle only passes through a bool. Ideally, I would have a single function in defaultScene:
void toggleObject3D(int index){
if(index >= 0 && index < visibleSize){
visible[index] = !visible[index];
}
}
So to make this work, I would need some sort of SIGNAL from traceMenu that would fire an int variable. I am unaware of such SIGNAL.