Qt How do I pass a QkeySequence to the qshortcut () function to work over a connection (signal, slot)?

I am trying to connect multiple shortcuts to a slot to get their key value and add it to a variable. Something like entering text, so I do something like this:

button_1 = new QShortcut::QShortcut(QKeySequence("1"),this);
connect(button_1,SIGNAL(activated(QKeySequence)),this, SLOT(keybord_shortcuts(QKeySequence)));

      

which is wrong because it activated()

won't get the sequence that triggers the shortcut for my slot keybord_shortcuts

.

No such signal QShortcut::activated(QKeySequence)

      

Is there any other way besides activated()

? Any help is greatly appreciated.

Thank.

+3


source to share


1 answer


Yes, there is activated(QKeySequence)

no such signal and you need to connect to the signal activated()

:

 connect(button_1, SIGNAL(activated()), this, SLOT(keybord_shortcuts()));

      



But you can get the real label in the slot using sender()

:

 void keybord_shortcuts()
 {
      QShortcut* shortcut = qobject_cast<QShortcut*>(sender());
      QKeySequence seq = shortcut->key();
      ...
 }

      

+3


source







All Articles