大家好,欢迎来到IT知识分享网。
Signals and Slots
Signals and slots are used for communication between objects. The signal/slot mechanism is a central feature of Qt and probably the part that differs most from other toolkits.
信号与插槽用于对象间通讯。信号/插槽机制是Qt的重要特征,这也许就是它与其它工具包差别最大之处。
In GUI programming we often want a change in one widget to be notified to another widget. More generally, we want objects of any kind to be able to communicate with one another. For example if we were parsing an XML file we might want to notify a list view that we’re using to represent the XML file’s structure whenever we encounter a new tag.
在图形用户界面编程中,我们常常希望一个窗口接收到其他窗口的通知之时做出改变。更普遍地,我们希望任意类型的对象能够与其它对象通讯。例如,在我们解析XML文件时,我们也许希望在遇到一个新的标记时,能够给一个我们用来显示XML文件的结构的列表发出通知。
Older toolkits achieve this kind of communication using callbacks. A callback is a pointer to a function, so if you want a processing function to notify you about some event you pass a pointer to another function (the callback) to the processing function. The processing function then calls the callback when appropriate. Callbacks have two fundamental flaws. Firstly they are not type safe. We can never be certain that the processing function will call the callback with the correct arguments. Secondly the callback is strongly coupled to the processing function since the processing function must know which callback to call.
老的工具包使用回调来达到这样的目的。回调是一个指向函数的指针,所以如果你希望一个处理函数通知你某些事件发生了,你可以传递一个指向其他函数的指针(回调)给处理函数。处理函数会在适当的时候调用回调函数。回调有两个基本缺点。第一,它不是类型安全的。我们不能保证处理函数会以正确的参数来回调。第二,回调与处理函数强耦合,因为处理函数必须知道哪个回调被调用。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/106211.html