How to pass a variable to a function called with a QShortcut?
Solved
General and Desktop
-
My attempt:
void Func(int x) { qDebug() << x << "\n"; } Test::Test(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_1), this); QObject::connect(shortcut, &QShortcut::activated, this, &Func(10)); return; }
I'm getting this error:
expression must be an lvalue or a function designator
atQObject::connect(shortcut, &QShortcut::activated, this, &Func(10));
-
Hi
You can use std::bind for such trick.QObject::connect(shortcut, &QShortcut::activated, this, std::bind(Func, 10));