• 5948阅读
  • 2回复

QT---在SLOT中如何获得触发SIGNAL的对象指针? [复制链接]

上一主题 下一主题
离线kelvinche
 
只看楼主 倒序阅读 楼主  发表于: 2009-07-29
— 本帖被 XChinux 执行加亮操作(2009-07-30) —
QT的SIGNAL-->SLOT模式确实很方便,但是有些时候需要在SLOT函数中辨别同一个SIGNAL是由哪个对象触发的,请问如何获取该对象?
离线rqzrqh

只看该作者 1楼 发表于: 2009-07-29
这个就由你传递的参数来表明,
设计信号槽的目的就是为了加强模块化而不需要对方是谁
离线yj_yulin

只看该作者 2楼 发表于: 2009-07-30
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 from this object's thread context.

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.

Warning: As mentioned above, the return value of this function is not valid when the slot is called via a Qt::DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.
快速回复
限100 字节
 
上一个 下一个