Results 1 to 6 of 6

Thread: SIGNAL and SLOT

  1. #1
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question SIGNAL and SLOT

    Hi, now I have to connect several SIGNALS to one SLOT, but how can I distinguish which QWidget emit the SIGNAL in the SLOT function??
    Is there any way to find the sender??
    Thanks !!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SIGNAL and SLOT

    one way is QObject::sender()other possibilities might be classes like QSignalMapper

  3. The following user says thank you to caduel for this useful post:

    sophister (24th April 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SIGNAL and SLOT

    Thanks!!
    Could I ask you one more question?
    when I use the QMap, something is always wrong. Following is my codes:
    in the .h file :
    Qt Code:
    1. QMap<QString, QToolButton*> buttons;
    To copy to clipboard, switch view to plain text mode 
    And I have added the declare at the beginning of the header file like this:
    Qt Code:
    1. class QMap<QString, QToolButton*>;
    To copy to clipboard, switch view to plain text mode 

    But I just can't pass the compiler.

  5. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SIGNAL and SLOT

    you need to write

    Qt Code:
    1. #include <QMap>
    2. #include <QString>
    3. class QToolButton; // forward decl ok as you just use a ptr to it
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SIGNAL and SLOT

    Thank you !!
    yeah, but I have forward declare for class QToolButton, and it's ok.
    if I haven't include QMap, and just forward declare it using
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    , the compiler will give some errors.
    The only way to use QMap in the header file is to
    Qt Code:
    1. #include <QMap>
    To copy to clipboard, switch view to plain text mode 
    , while just using forward declare won't work.
    I'm really puzzled

  7. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SIGNAL and SLOT

    well, the compiler needs to know more here: QMap is a templated type.
    If you write QMap, the compiler assumes QMap is a 'plain' type and then writing QMap<T1,T2> is not ok, just as you may not write QString<int>.

Similar Threads

  1. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  2. retrieving signal name in a slot
    By Baschterl in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 20:44
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.