Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Boost.Signal instead of Qt's signals? Do without moc?

Tags:

c++

boost

qt

moc

I know they can be used together, but I'm wondering whether it's possible to replace Qt's signals and slots mechanism with Boost.Signal in the Qt parts of the program (widgets and such).

Anyone ever try it? Any gotchas?

Assuming I don't use any other MOC features and replace signals/slots with boost.signal, is it possible to do without moc entirely?

like image 860
drby Avatar asked Jan 19 '10 10:01

drby


People also ask

Why does Qt use moc for signals and slots?

Qt's moc (Meta Object Compiler) provides a clean way to go beyond the compiled language's facilities. It does so by generating additional C++ code which can be compiled by any standard C++ compiler.

What is moc in Qt?

The Meta-Object Compiler, moc , is the program that handles Qt's C++ extensions. The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes.

What are boost signals?

The Boost. Signals library is an implementation of a managed signals and slots system. Signals represent callbacks with multiple targets, and are also called publishers or events in similar systems.


2 Answers

I considered it for one of my projects. One aspect that might bother you, depending on the project is the use of Qt Designer. The Qt-Designer creates signal-slots underneath for its GUI connections. So, if you happen to use the designer, you will end up with projects having both signals-slots and boost::signals. There are some issues with using them together f.e. see this blog. Though its possible for them to work together, i would refrain from mixing the two approaches.

But the biggest problem i faced was that boost::signals are not thread-safe whereas Qt's signal-slot is! So it was easy decision for me as my project was multithreaded.

You can get the relative merits and de-merits of the approach taken by boost and Qt from Page-11 of this PDF.

HTH

like image 87
Abhay Avatar answered Sep 20 '22 02:09

Abhay


I don't think that is something you want to do. Qt's signals are deeply integrated in the framework and how they are generated and handled. Don't waste your time :)

like image 27
fabrizioM Avatar answered Sep 21 '22 02:09

fabrizioM