Qt 中的接口隔离
我总是尝试应用 SOLID 原则,我真的很喜欢 Qt 工具包,但我发现自己一直在使用 单继承规则。
如果您使用多重继承, moc 假设第一个继承的 类是 QObject 的子类。 此外,请确保只有第一个继承类是 QObject。
如何将 QObject 规则的单一继承与接口隔离原则结合起来。
我想用信号和槽定义接口,但我不允许这样做。
如何克服这个缺点?
I always try to apply the S.O.L.I.D principles and I really like the Qt toolkit but I find myself stuggeling all the time with the single inheritance rule.
If you are using multiple inheritance,
moc assumes that the first inherited
class is a subclass of QObject.
Also, be sure that only the first inherited class is a QObject.
How do you combine the single inheritance from a QObject rule and the Interface Segregation Principle.
I want to define the interfaces with signals and slots, but I'm not allowed to do this.
How do you get around this shortcomming?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请记住,信号和槽只不过是具有特殊行为的函数。因此,您可以使用它们来创建接口。
有关该过程的完整说明以及复杂情况的完整解决方法,请参阅 Qt 季刊#15。
Keep in mind that signals and slots are nothing more than functions that have special behaviors. Thus, you can use them to create interfaces.
For a full description of the process and a complete workaround for complex cases, see Qt Quarterly #15.
我不认为你可以使用 Qt 的信号/槽机制轻松解决这个问题。您可以尝试查看 boost::signals 或 sigc 库,它们在放置信号和槽的位置上都更加灵活。请注意与任一库以及 Qt 的
signals
和slots
宏可能发生的命名空间冲突。I don't think you can easily get around that with Qt's signal/slot mechanisms. You could try looking at either boost::signals or the sigc library, which are both more flexible in where you can place signals and slots. Be aware of possible namespace collisions with either library and Qt's
signals
andslots
macros.