QT中的按钮问题

小_柒 2008-09-19 11:38:42
我定义了一组按钮,这组按钮共用一个槽,如何确定点击了哪个按钮?
QPushButton *button[10];
for(int i=0; i<10; i++)
{
button = new QPushButton("test");
connect(button, SIGNAL(clicked()), this, SLOT(mySlot()));
}
就是上面这个mySlot()该如何定义和实现?
谢谢!
...全文
205 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
arrow_swpi 2008-12-10
  • 打赏
  • 举报
回复
void MyClass::mySlot()
{
//sender为信号发送者
QObject *obj=sender();

if(obj==button[0])
{
qDebug("button 0 clicked");
}
else if(obj==button[1])
{
qDebug("button 1 clicked");
}
else if ...
}


--------------------------
另外:你的上面的代码
button = new QPushButton("test");
似乎应该修改为:button[i]= new QPushButton("test");
mifeixq 2008-09-19
  • 打赏
  • 举报
回复
友情up,我只会gtk。。。
小_柒 2008-09-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zjw6861982 的回复:]
把按钮的资源号搞到一个数组中,查找就行了
[/Quote]

能不能详细说明一下?
小_柒 2008-09-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 bitxinhai 的回复:]
new QPushButton("test"); 使用不同的名字!!!
[/Quote]

实际程序中我是使用不同名字的
bitxinhai 2008-09-19
  • 打赏
  • 举报
回复
new QPushButton("test"); 使用不同的名字!!!
zjw6861982 2008-09-19
  • 打赏
  • 举报
回复
把按钮的资源号搞到一个数组中,查找就行了
allenpettle 2008-09-19
  • 打赏
  • 举报
回复
使用QThread定义两个线程,一个鼠标响应事件,一个按钮查找事件。

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧