|
Qt's signals and slots mechanism: not very good? |
axilmar
Member #1,204
April 2001
|
Qt's signals & slots mechanism is of dubious usefulness, to say the least. In the current project I am working on, I had to use the MOC compiler manually (old Qt version, IDE does not support integration with this old Qt version), and it's very cumbersome to do so every time there is a change in the design of the software. And Qt does not throw an exception if a slot is wrongly connected to a signal, it only outputs a debug message, so one has to be very careful about what happens. I decided that I've had enough with it, and I've coded my own Slot classes, which are templates. Here is the code for a slot with 1 parameter:
It works like a charm: I can write the following code (for example): connect(button, SIGNAL(clicked()), myObject, &MyObject::method); So why Trolltech does not provide these classes? for me, it's for economic reasons, i.e. forcing people to buy new licenses in order to get integration with newer environments. There is no technical problem in using signals with slot classes. |
juvinious
Member #5,145
October 2004
|
Attached is what I use for my GUI lib, I modified the version that is from here. I cleaned up some of the code that had issues and added in signal chaining. So to use for one signal like you did above would be like:
__________________________________________ |
Jonny Cook
Member #4,055
November 2003
|
I never found it that annoying. Qts method is a lot more flexible, and will work with an arbitrary amount of arguments. And you can also do cool things like have it auto connect methods with certain names. The face of a child can say it all, especially the mouth part of the face. |
axilmar
Member #1,204
April 2001
|
Quote: I never found it that annoying. Neither did I when I used VS6 which Qt integrated with nicely. But with VS8, Qt 3.0.5 does not have integration, so I am obliged to invoke the MOC manually. Aren't you bothered by the fact that Qt is silent when a connection fails? |
Mokkan
Member #4,355
February 2004
|
I've never had problems with Qt's slots/signals, and I've always had to 'manually' invoke moc. I've found that it isn't difficult to add moc to makefiles, scons projects, or cmake projects. Congrats on making your own though. Whatever works for you.
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: Aren't you bothered by the fact that Qt is silent when a connection fails? Connections don't fail. they just might not be all that usefull if you're connecting to a signal thats not going to fire. Also, if you dislike calling moc yourself, use qmake. it does all the moc, and uic goodness for you. -- |
axilmar
Member #1,204
April 2001
|
Quote: Connections don't fail. They do. If you mispell a signal or slot or a parameter inside a SIGNAL() or SLOT() expression, the only thing Qt will do is to output a warning message in the debug output. At least that's what version 3.0.5 does. Quote: Also, if you dislike calling moc yourself, use qmake. it does all the moc, and uic goodness for you. I have no idea if qmake can be used instead of Microsoft's compiler inside the VS8 IDE. |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: They do. If you mispell a signal or slot or a parameter inside a SIGNAL() or SLOT() expression, the only thing Qt will do is to output a warning message in the debug output. At least that's what version 3.0.5 does. Right, it didn't fail at all. It connected a signal to a slot, just not the ones you wanted it too because you can't type Quote: I have no idea if qmake can be used instead of Microsoft's compiler inside the VS8 IDE. They have a VS plugin for Qt. -- |
axilmar
Member #1,204
April 2001
|
Quote: Right, it didn't fail at all. It connected a signal to a slot, just not the ones you wanted it too because you can't type Agreed. But that's human nature: sometimes you don't type what you should. And then there is the problem of changing stuff: if you change a signal's signature and you forget to update the slots, the program will run normally. My point is that the Qt signals & slots mechanism is more dangerous than using classes. With classes, the compiler makes sure the code works. Quote: They have a VS plugin for Qt. In order to get integration with VS8 you have to buy a new Qt version. |
|