void Dialog::mousePressEvent(QMouseEvent *e){ QPushButton *button_clicked = qobject_cast<QPushButton *>(sender()); ... ... ...}
QPushButton *button = new QPushButton;button->setText("-");button->setObjectName(name);connect(button,SIGNAL(clicked()),this,SLOT(RemoveItem()));
QObject *element = (QObject *)sender();QString name=element->objectName();
connect(button,SIGNAL(clicked()),this,SLOT(RemoveItem()));
C++ (Qt)void NumberButton::mousePressEvent(QMouseEvent* e){ QPushButton::mousePressEvent(e); bool error; uint number = text().toUInt(&error); if ( error || number > 9 ) { qt_assert_x("error", "wrong number", __FILE__, __LINE__); } else { // обработчик нажатой цифровой кнопки на калькуляторе numberPressed( number ); }}
void Dialog::finished(){ QSignalMapper *signalMapper; for(int i=0; i<10; i++) { QString button_name = "num_" + QString::number(i); connect(button_name,SIGNAL(clicked()),signalMapper,SLOT(map())); signalMapper->setMapping(button_name,QString::number(i)); connect(signalMapper, SIGNAL(mapped(const QString &)), this, SLOT(clicked(const QString &))); }}