天天看点

如何绑定多个action到一个slot

1.设置userdata,并将多个action绑定到同一个slot 

 a->setData(action); //这里的action可以是一个qvariant值

    connect(a, SIGNAL(triggered(bool)),

            this, SLOT(actionslot(bool)));

void actionslot(bool)

{

   QAction *a = qobject_cast<QAction *>(q->sender());

    if (!a)

        return;

    int action =a->data().toInt(); //通过这里来区分是哪个actiontriggered

    //do something your own

}