• 5933阅读
  • 3回复

请问 怎样获取 产生事件的对象的信息?fjb [复制链接]

上一主题 下一主题
离线hantong
 
只看楼主 倒序阅读 楼主  发表于: 2008-06-26
— 本帖被 XChinux 执行加亮操作(2008-06-27) —
比如: 单击了一个按钮,我想在处理函数中 得到 这个按钮的 名字 文本。。

谢!
离线XChinux

只看该作者 1楼 发表于: 2008-06-27
比如:
QPushButton *button = qobject_cast<QPushButton *>(sender());
QString text = button->text();
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线yj_yulin

只看该作者 2楼 发表于: 2008-06-27
QObject * QObject::sender () const  [protected]
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function.
The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.
Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.
See also QSignalMapper.
离线hantong
只看该作者 3楼 发表于: 2008-06-27
谢谢  问题解决
快速回复
限100 字节
 
上一个 下一个