Results 1 to 20 of 24

Thread: Connect slot to an int function !?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Connect slot to an int function !?

    johnc is right, but I don't see what use is the signal mapper here.
    The signal mapper is good for when you have multiple dynamic, only in run time determined controls that need to be connected to slots by some rules.
    But for finite number of known objects, I am not sure if using the a signal mapper is really less coding, or has any other advantage over regular old school connections.
    You can implement the same functionality as the signal mapper by just connecting to one slot, and in the slot do:
    Qt Code:
    1. void MyClass::mySmartSlot()
    2. {
    3. switch(sender())
    4. {
    5. case pButton1: //do button stuff;
    6. break;
    7. case pButton2: // do button 2 stuff;
    8. break;
    9. //or even
    10. case pLineEdit: //we can even do other control stuff with the same slot
    11. break;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    This approach gives far more flexibility, and is not more coding.
    But this is usually not needed.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. The following user says thank you to high_flyer for this useful post:

    hakermania (29th December 2010)

Similar Threads

  1. connect between function of two differents QWidget
    By shenakan in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2010, 18:32
  2. Can't connect a signal to a slot
    By cejohnsonsr in forum Newbie
    Replies: 5
    Last Post: 26th August 2010, 20:42
  3. connect a QPushButton matrix with a function
    By harmodrew in forum Newbie
    Replies: 6
    Last Post: 6th August 2010, 11:11
  4. QObject::connect: No such slot !?!
    By Mystical Groovy in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 18:31
  5. Qt Designer & Qt4, connect to my own slot.
    By geitosten in forum Newbie
    Replies: 2
    Last Post: 17th February 2007, 19:22

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.