Results 1 to 6 of 6

Thread: Slot

  1. #1
    Join Date
    Nov 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Slot

    Hello,

    What is wrong with:
    menu->addAction("Curve 1",this, SLOT(addGraph(QString("Curve 1"))));

    I want to give the function addGraph the argument "Curve 1".

    Regards,
    Arend

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot

    You cannot pass argument values to Signal/Slot connects, the arguments are always provided by the signal and passed to the slot.

    In your case, where you have a signal without argument and want the slot to be called with a single string argument, the best way forward is to use QSignalMapper.

    Create a QSignalMapper instance and use it as the receiver for addAction(), using SLOT(map()).
    Then add a mapping from your action to the desired string and connection the signal mapper's mapped(QString) signal to your slot

    Something like this
    Qt Code:
    1. QSignalMapper *mapper = new QSignalMapper( this );
    2. connect( mapper, SIGNAL(mapped(QString)), this, SLOT(addGraph(QString)) );
    3.  
    4. QAction *action = menu->addAction( "Curve 1", mapper, SLOT(map()) );
    5. mapper->setMapping( action, "Curve 1" );
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Arend (25th November 2012)

  4. #3
    Join Date
    Nov 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Slot

    Thanks for the quick answer, but how to add a second curve?

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slot

    Read the docs for QSignalMapper, understand what it is doing, and repeat the mapping exercise for the second, third, fourth, and subsequent signals.

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot

    Quote Originally Posted by Arend View Post
    Thanks for the quick answer, but how to add a second curve?
    Repeat lines 4 and 5

    Cheers,
    _

  7. #6

    Default Re: Slot

    Thanks for the post...
    lord

Similar Threads

  1. No Such Slot
    By Geoffry31 in forum Newbie
    Replies: 9
    Last Post: 13th November 2012, 22:07
  2. Replies: 8
    Last Post: 7th November 2012, 14:10
  3. Replies: 2
    Last Post: 26th August 2011, 08:51
  4. Slot
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2006, 18:51
  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
  •  
Qt is a trademark of The Qt Company.