View Full Version : Slot
Arend
24th November 2012, 10:10
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
anda_skoa
24th November 2012, 11:13
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
QSignalMapper *mapper = new QSignalMapper( this );
connect( mapper, SIGNAL(mapped(QString)), this, SLOT(addGraph(QString)) );
QAction *action = menu->addAction( "Curve 1", mapper, SLOT(map()) );
mapper->setMapping( action, "Curve 1" );
Cheers,
_
Arend
25th November 2012, 19:38
Thanks for the quick answer, but how to add a second curve?
ChrisW67
25th November 2012, 21:41
Read the docs for QSignalMapper (http://qt-project.org/doc/qt-4.8/qsignalmapper.html), understand what it is doing, and repeat the mapping exercise for the second, third, fourth, and subsequent signals.
anda_skoa
26th November 2012, 19:21
Thanks for the quick answer, but how to add a second curve?
Repeat lines 4 and 5
Cheers,
_
lordkevin
29th November 2012, 06:18
Thanks for the post...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.