• 8258阅读
  • 4回复

如何判断触发同一槽的不同的信号发送者!? [复制链接]

上一主题 下一主题
离线zsw8766
 

只看楼主 倒序阅读 楼主  发表于: 2010-03-31
槽函数里能判断触发该槽的信号的发送者吗?

我要实现的是:菜单ActonOpen的单击事件和菜单AcionNew的单击事件都能触发QtreeWidget的show事件,QtreeWidget根据不同触发者(是谁发送的单击信号),来发送不同的信号,以激发不同的槽
离线benbenmajia

只看该作者 1楼 发表于: 2010-03-31
自己编写信号槽
安然.....
离线dbzhang800

只看该作者 2楼 发表于: 2010-03-31
引用楼主zsw8766于2010-03-31 10:22发表的 如何判断触发同一槽的不同的信号发送者!? :
槽函数里能判断触发该槽的信号的发送者吗?

我要实现的是:菜单ActonOpen的单击事件和菜单AcionNew的单击事件都能触发QtreeWidget的show事件,QtreeWidget根据不同触发者(是谁发送的单击信号),来发送不同的信号,以激发不同的槽


from manual:
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.

See also QSignalMapper.
离线yangfanxing
只看该作者 3楼 发表于: 2010-03-31
在slot中,QAction *theClickedAction=  dynamic_cast<QAction*>(sender());
theClickedAction为sender的指针,比较winID等判断是哪个ACtion触发的事件。
PHPWind好恶心。。。不想看这种界面。。。
离线luoyes

只看该作者 4楼 发表于: 2010-03-31
用sender()
快速回复
限100 字节
 
上一个 下一个