关于获得点击获得QPushButton值的问题???
刚学习Qt没有几天,在做一个简单的计算器时就遇到了一个问题。计算器+,-,*,/四个运算符按钮,我使用的是pushButton,这就产生了一个问题。当我点击这四个按钮中的任何一个之后,有没有简单的方法就可以获得按钮中的值。即四个按钮对应一个槽???这个问题困扰了我不少时间,希望大家帮帮忙!!! Qt pushbutton 槽
[解决办法]
pAddButton = new QPushButton("AddButton",this);
pSubButton = new QPushButton("SubButton",this);
pMulButton = new QPushButton("MulButton",this);
pDivButton = new QPushButton("DivButton",this);
pAddButton->setObjectName("AddButton");
pSubButton->setObjectName("SubButton");
pMulButton->setObjectName("MulButton");
pDivButton->setObjectName("DivButton");
connect(pAddButton,SIGNAL(clicked()),this,SLOT(ButtonSlot()));
connect(pSubButton,SIGNAL(clicked()),this,SLOT(ButtonSlot()));
connect(pMulButton,SIGNAL(clicked()),this,SLOT(ButtonSlot()));
connect(pDivButton,SIGNAL(clicked()),this,SLOT(ButtonSlot()));
void ButtonSlot()
{
QString buttonName = sender()->objectName();
if (buttonName.compare("AddButton") == 0)
{
}
else if (buttonName.compare("SubButton") == 0)
{
}
else if (buttonName.compare("MulButton") == 0)
{
}
else if (buttonName.compare("DivButton") == 0)
{
}
}