如何在Qt子类中处理信号?
如何处理子类中的信号?假设我的子类派生自 QTextEdit
并且对信号 textChanged
感兴趣。将对象连接到自身似乎很愚蠢,我应该能够简单地重写 textChange
方法 - 但它不是虚拟
。
接受的方法是什么?
How do I process a signal of in a subclass? Let's say my subclass is derived from QTextEdit
and is interested in the signal textChanged
. It seems silly to connect an object to itself, I should be able to simply override the textChange
method -- but it isn't virtual
.
What is the accepted way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法实现/覆盖信号,因此唯一的方法是创建一个新插槽并将其连接到 textChanged():
You can't implement/override a signal, so the only way is to create a new slot and connect it to textChanged():
也许这看起来很愚蠢,但这就是我所做的:将我的派生类连接到父类发出的信号。
但我很感兴趣是否还有其他解决方案!
Maybe it seems silly, but that's the way I did it : connecting my derived class to the signal emited by the parent class.
But I'm interested if there are any other solutions !
将信号连接到同一类中的插槽是完全可以的。
因此,实现您的插槽并将其连接到
textChanged(QString)
It is perfectly ok to connect a signal to a slot in the same class.
So implement your slot and connect it to
textChanged(QString)