Op 27-12-2012 15:35, Oleg Yarigin schreef: > Hello, > > I read http://byuu.org/articles/qt and got a question, why Qt uses slots and > signals? That blog is outdated, incomplete and biased. I am not claiming Qt is without bugs, but... > That stuff can be safe replaced with function pointers. I am sure, it can > give some advantages. Such as? Big claims require big evidence, and you're offering none. > > For instance, for now we need to use something like this to connect callbacks > (actions): > > connect( <a>, <a`s action>, <b>, <b`s slot> ); > > then we use moc, Q_OBJECT macro and special "slots:" class section. There is nothing special about 'slots:' or 'signals:' or even 'emit'. You don't even need to use them if you don't want to. Use Q_SLOT or Q_SIGNAL instead if you prefer, and if you want, you can leave out the emit completely. > > I hope, this stuff can be better (with a way below we do not need to use moc, > qmake and have an overhead in Qt library): > > > What do you think about it? If you are agree, I will create a new brunch in > Qt repo for making these changes. You clearly have no clue what you're talking about. First of all, you *can* use function pointers (instead of slots) now for your connections. And yes, that includes lambda functions. Second, moc and Q_OBJECT does a good deal more than just dealing with signals and slots.
3rd, Qt's signals and slots do a lot more than a vanilla function pointer will ever do. Or can that transparently handle threading? Queued connections, blocking if needed? Type safety? Provide information on who triggered the signal? Work with mis-matched argument lists? Work with signal-signal connections? Provide many-to-many relationships between the caller (signal) and the callee (slot)? Signals & slots do provide all that. Other toolkits have also seen all this value, and actually copied the concept. Boost for instance: http://www.boost.org/doc/libs/1_52_0/doc/html/signals.html But most of Qt's implementation was already working just fine long before the advanced template stuff needed for boost to work was broadly available... André _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest