PDA

View Full Version : How to get event name in slot



Toasted
13th July 2010, 15:54
I am writing Qt event record software. I want to create a single slot that can record the sending object and the signal type.



connect(myButton, SIGNAL(clicked()), this, SLOT(mySlot()));
connect(myMenuAction, SIGNAL(triggered()), this, SLOT(mySlot()));

void mySlot()
{
QString senderName = sender()->objectName();
QString signalName = ? // is it clicked or triggered?
}


Thanks.

axeljaeger
13th July 2010, 19:21
Bad things you want to do. Just use two different slots. Why first merge events to split them up again later? Remember that you should not even use sender(). Either both the button and the action do the same, then you do not need to act different, or they are doing something different, then use different slots.

Toasted
13th July 2010, 19:37
I know it looks bad, but it is actually not as stupid as it looks. All I want is to log all signals. So I have this slot which just logs the sender and the signal to a text file. I could do it one slot for each one, but I have more than a hundred slots in my application, so this would be much simpler.

So is there a way? I can't find one in the Qt doc.

Thanks again.

axeljaeger
13th July 2010, 19:43
I see. Does http://doc.trolltech.com/4.6/qsignalspy.html help in any way? I guess you would have to create a hundred of these objects but at least this can be done inside a loop in contrast to a loop.

Another option is to use a QSignalMapper and add the name of the signal as an argument to the signature of every signal.