16,201
社区成员
发帖
与我相关
我的任务
分享
class MyPushButton : public QPushButton
{
Q_OBJECT
public:
explicit MyPushButton(int index, QWidget *parent = 0) : QPushButton(parent), index(index)
{
connect(this, SIGNAL(clicked()), this, SLOT(OnClicked()));
}
private:
int index;
public slots:
void OnClicked(){qDebug() << index;//你可以在这里emit(index),槽函数就可以根据index知道是哪个按钮发出的信号}
};
下面几行是创建BUTTON的代码
for(int i = 0; i < 3; i++)
{
MyPushButton *button = new MyPushButton(i, this);
button->setText("button" + QString::number(i));
button->move(120 * i + 10, 100);
button->show();
}