Qt C++ 中不同类的信号/槽功能
对于一个类,我声明了一个槽和一个信号,并且在槽方法定义中,我使用emit关键字调用信号方法。但是我怎样才能将一个类的信号发送到另一个有插槽的类。
好吧,我尝试使用按钮来修改标签文本。按钮由 A 类创建(必须发出信号),标签由 B 类创建,该类必须有一个槽来修改其上的文本
For just one class , i declare a slot and a signal , and in slot method definition i call signal method with emit keyword. But how can i emit signals with one class to another class which has a slot.
Well i try with a button to modify a label text. Button is created by A class (which must emit a signal) , and label is created by class B which must have a slot to modify text on it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来你有类 1,它有一个将被执行的方法,并将调用“emit”。当这种情况发生时,另一个班级的插槽就会发现。
第一类的定义:
第二类的定义:
以及你的主程序:
It seems like you have class 1, which has a method that will be executed, and will call "emit". When that happens, the slot of another class will find out.
definition of 1st class:
definition of class 2:
and your main program:
在名为
void emitSignalBlahBlah()
的类中添加一个公共方法,作为emit
代码的包装器。然后,所有其他需要触发此信号的类将访问此对象并调用该方法来执行此操作。Add a public method in the class named
void emitSignalBlahBlah()
to be a wrapper around theemit
code. Then, all the other classes that need to fire this signal will access this object and call the method to do it.