Qt Shortcut Keys activated signals
-
I noticed that my code as shown below executes the slot function twice. So the integer being changed either has 1 added twice or subtracted twice. Is this intended or is there a way around this?
QShortcut *add= new QShortcut(Qt::Key_Plus, this); QShortcut *sub= new QShortcut(Qt::Key_hyphen this); QSignalMapper *mapper = new QSignalMapper(this); QObject::connect(next, SIGNAL(activated()), mapper, SLOT(map())); QObject::connect(prev, SIGNAL(activated()), mapper, SLOT(map())); mapper->setMapping(next, 1); mapper->setMapping(prev, -1); QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int))); QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
-
Hi
Ï think the double issue comes from thisQObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));That would fire it twice for an int since they are 100% identical.
-
Hi @Akito_Kami ...
try using Qt::UniqueConnection in connect statement... hope problem gets resolved.
-
Hi
Ï think the double issue comes from thisQObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));That would fire it twice for an int since they are 100% identical.
@mrjj Thanks. Removing one of the statements worked.