Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how would I pass value to SLOT function ?

how would I pass value to SLOT function ?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mit_cruzeM Offline
    mit_cruzeM Offline
    mit_cruze
    wrote on last edited by
    #1
    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)

    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

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

      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);
      
      

      -Michael.

      mit_cruzeM 1 Reply Last reply
      0
      • D Offline
        D Offline
        Devopia53
        wrote on last edited by Devopia53
        #3

        The simplest way is something like this:

        connect(snapshot_action[k], &QAction::triggered, [&, k]{ snap_fun(k); });
        
        mit_cruzeM 1 Reply Last reply
        2
        • m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • D Devopia53

            The simplest way is something like this:

            connect(snapshot_action[k], &QAction::triggered, [&, k]{ snap_fun(k); });
            
            mit_cruzeM Offline
            mit_cruzeM Offline
            mit_cruze
            wrote on last edited by
            #5

            @Devopia53 Thanks Dude!

            1 Reply Last reply
            0
            • m.sueM m.sue

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

              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);
              
              

              -Michael.

              mit_cruzeM Offline
              mit_cruzeM Offline
              mit_cruze
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved