简体   繁体   中英

Efficiency of Qt Signals and Slots

I was browsing the methods inside of QMainWindow and noticed that some parts (such as resizeEvent and winEvent) are not implemented as signals but rather you have to inherit this class to be able to override them.

My question is, how efficient are signals and slots and would it be possible to implement these types of functions as signals from which other classes can subscribe to. For instance, inside of a high performance game engine.

From what I recall, Trolltech stated that a signal/slot call is about 10 times slower than a virtual call. You should be able to easily process tens, if not hundreds of thousands signals per second.

Signal and slots are designed so that different objects can communicate, both objects being under your control.

The events you mention involve only one object at a time, which gets directly notified by the event loop. There is no need for signals or slots here.

Note that you can emit a signal inside an event member function if you want to. This is often the right way to react to an event. This way, other objects can subscribe to something.

如果您想在其他地方对此类信号做出反应,则从QMainWindow派生,重新实现resize()并从那里发出()信号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM