0
for(int i=0;i<2;i++)  { for(int j=0;j<2,j++)  {
        snapshot_action[k]=new QAction(this);
        snapshot_action[k]->setIconText("Snapshot");
        control_menu[k]->addAction(snapshot_action[k]);
        connect(snapshot_action[k], &QAction::triggered, this, &SimplePlayer::snap_fun);}}

With initially k=0; I have omitted code which lays out four views each with snapshot action. ( for simplicity).

Now the problem is when I press snapshot action button of any view I should know somehow that snapshot action button of THAT particular window is pressed.

How can I?

How would I pass value of to my snap function?

Do I need to store values of 'k' in some array? (some bad idea)

demonplus
  • 5,613
  • 12
  • 49
  • 68
Mitesh Patel
  • 465
  • 2
  • 5
  • 14

1 Answers1

1

You can use a QSignalMapper:

QSignalMapper m_mapWidget;

In the code:

connect(&m_mapWidget, SIGNAL(mapped(int)), this, SLOT(snap_fun_k(int)));

loop k:

connect(action, SIGNAL(triggered()), &m_mapWidget, SLOT(map()));
m_mapWidget.setMapping(action, k);

Note that you'll want the lifetime of the signal mapper to be at least as long as you want it to perform the mapping.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Mitesh Patel
  • 465
  • 2
  • 5
  • 14