I wrote a minimal, complete sample. In my case, it worked as you described it. Maybe I added something that you did not do on your side. (This is why “minimal, complete, tested samples” are preferred.)
#include <iostream>
#include <QAction>
#include <QApplication>
#include <QLabel>
#include <QMainWindow>
using namespace std;
int main(int argc, char **argv)
{
cout << QT_VERSION_STR << endl;
#undef qApp
QApplication qApp(argc, argv);
const char *shortCut = "Ctrl+Shift+Q";
QMainWindow qWin;
QAction qCmdCtrlShiftQ(&qWin);
qCmdCtrlShiftQ.setShortcut(QKeySequence(shortCut));
qWin.addAction(&qCmdCtrlShiftQ);
QLabel qLbl(
QString::fromLatin1("Please, press ")
+ QString::fromLatin1(shortCut));
qLbl.setAlignment(Qt::AlignCenter);
qWin.setCentralWidget(&qLbl);
qWin.show();
QObject::connect(&qCmdCtrlShiftQ, &QAction::triggered,
[&qLbl, shortCut](bool) {
qLbl.setText(
QString::fromLatin1(shortCut)
+ QString::fromLatin1(" pressed."));
});
return qApp.exec();
}
, QWidget::addAction()
. , .
VS2013 Qt 5.6 Windows 10 (64 ):
Ctrl + Shift + Q.
:
, "Ctrl + Shift + C". , . "Ctrl + Shift + C".