Important: Please read the Qt Code of Conduct -

how would I pass value to SLOT function ?

  • for(int i=0;i<2;i++)  
       for(int j=0;j<2,j++)
            snapshot_action[k]=new QAction(this);
            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)

  • Hi,
    I usually do such things with the QSignalMapper class. E.g.:
    In the header:

    QSignalMapper m_mapWidget;

    In the code:

    loop k:


  • The simplest way is something like this:

    connect(snapshot_action[k], &QAction::triggered, [&, k]{ snap_fun(k); });

  • Indeed! I see I am not yet used to the lambda-stuff :-)

  • @Devopia53 Thanks Dude!

  • @m.sue Thanks Dude! your solution Worked!!!

Log in to reply