Qt and boost comparison instructions for signals and slots

Source: Internet
Author: User


Compare

No matter how Qt is implemented or how Boost is implemented, no additional classes are required except for the classes that define the signals and slots that must be defined.

Both implementations solve the problem of class explosion. Let's take a look at our previous analysis.

    • Two different terms and their respective movements: signals and slots ;

    • In a place (signal) can connect 0 or more callback functions (slots) is also many-to-many, one-to-many, many- to-many ;

    • The focus is on the connection itself , not the provider or the consumer;

    • no need to manually create a new class for a connection ;

    • The connection is still type-safe .

These five points are at the heart of the signal slot system, and both Qt and boost have these features.

The following are the differences between the two:

Boost.signals Qt Signals and Slots
Signal A signal is an object.
Global, local, or member object
Signal can only be a member function
Call Emits a signal similar to a function call
Any code that has access to the signal object can send a signal.
Emits a signal similar to a function call
QT provides a emit keyword to complete this operation
Only the owner of the signal can send a signal.
Slot A slot is any function or function object that can be called Slots are specially designed member functions
return value Can I have a return value? , the return value can be used in multiple slots No return value
Synchronous asynchronous Synchronous Synchronous or (direct-attached) person Async (queue)
Thread Safety Non-thread safe? Thread-safe, can be used across threads
Signal Disconnect When and only if the slots are traceable? , the connection is automatically disconnected when the slot is destroyed When the slot is destroyed, the connection will automatically disconnect (because all slots are traceable)
Type safety Type safety (compiler Check) Type safety (run-time check)
Parameter list Parameter list must be exactly the same slots can ignore excess parameters in the signal (signal parameters can be more than slots)
Signal, slot can be a template Signal, slot cannot be a template
The underlying implementation Direct implementation of C + + Implemented by the MOC-generated meta-object (MOC and meta-object systems are directly implemented in C + +)
Introspection No introspection mechanism Can be found through introspection

Can be called from a meta object

The connection can be automatically inferred from the resource file

? is a place of doubt. It's not understood at the moment

Most importantly, the signal slot mechanism of Qt has been deeply embedded into the framework and is an integral part of it. They can be easily created, deleted, and modified using Qt-specific development tools, such as Qtcreator, in a drag-and-drop fashion. They can even be automatically generated dynamically by dynamically loading resource files and by specific named objects. These are not available in boost as a universal repository.

--------------------------------------------------------------------------------------------------------------- --------------------

Reprint Address: http://no001.blog.51cto.com/1142339/1335733/

Qt and boost comparison instructions for signals and slots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.