Getting the button pressed after clicking () is called in Qt (C ++)

I was wondering, once the clicked () button is selected by the button, is there a way to find out which button selected it without overloading the click () function? (I have a bunch of buttons with almost the same function, but with different text, which is the defining element of each button).

Thanks in advance!

+3
source share
2 answers

In a slot, you can call the function sender()to get the QObject, which has sent you a signal clicked(). It returns a QObject *. Use qobject_castto translate QObject *to QPushButton *.

The documentation is here .

+10
source

, QSignalMapper.

, , , clicked() map() , setMapping( QObject * sender, const QString & text ). mapped( const QString & text ) , .

+6

Source: https://habr.com/ru/post/1749974/


All Articles