Results 1 to 4 of 4

Thread: How to get event name in slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to get event name in slot

    I am writing Qt event record software. I want to create a single slot that can record the sending object and the signal type.

    Qt Code:
    1. connect(myButton, SIGNAL(clicked()), this, SLOT(mySlot()));
    2. connect(myMenuAction, SIGNAL(triggered()), this, SLOT(mySlot()));
    3.  
    4. void mySlot()
    5. {
    6. QString senderName = sender()->objectName();
    7. QString signalName = ? // is it clicked or triggered?
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Platforms
    MacOS X Unix/X11
    Thanks
    1
    Thanked 52 Times in 52 Posts

    Default Re: How to get event name in slot

    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.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get event name in slot

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Platforms
    MacOS X Unix/X11
    Thanks
    1
    Thanked 52 Times in 52 Posts

    Default Re: How to get event name in slot

    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.
    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Replies: 2
    Last Post: 24th October 2009, 23:45
  2. Event Loop started in slot function
    By elizabeth.h1 in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2009, 12:56
  3. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  4. Replies: 3
    Last Post: 20th February 2007, 13:02
  5. What's the relationship between signal/slot and event?
    By twosnowman in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 17:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.