Difference between signals and slots in Qt and LibEvent

Viewed 470

Maybe it's a very strange question for someone, but what is the difference between signals and slots system in Qt and LibEvent library? Because it seems that they both used for something similar.

Why I need to use LibEvent if I already have signals and slots in Qt? What is better to use to manage a large number of network connections and how? E.g. I need to use LibEvent or signals and slots in the SSL via TCP server.

1 Answers

Both Qt signal/slot and libevent relies on callbacks, while they are quite different in mechanism and use case.

Qt slot is plain function.While Qt siganl is basically container of callbacks, you can image it likes std::list<CALLBACK_FUNC>. While you 'emit' a signal, you actually call each slot function from the 'emit' directly. Qt signal/slot is based on c/c++ function pointer and runtime typeinfo (generated by moc and Q_OBJECT magic), and can be used to connect any C++ class instance.

Libevent callbacks are invoked from event loop, usually you don't want call them directly. And libevent callbacks are served for predefined 'events', you can not use them for generic purpose.

If you plan to implement Qt app with network communication, I suggest that you can use Qt sockects, which integrate well with Qt event loop.

Related