我想将两个整数(string 和 fret)发送到一个 SLOT,该 SLOT 将处理按下的按钮的位置。 SIGNAL 和 SLOT 参数必须匹配,所以我想我需要重新实现 QPushButton::clicked 事件方法。问题是我是 Qt 的新手,需要一些指导。
connect(&fretBoardButton[string][fret], SIGNAL(clicked()), this, SLOT (testSlot()));
最佳答案
如果您使用 C++11 connection syntax您可以使用带有 string
和 fret
参数的调用 testSlot
的 lambda:
connect(&fretBoard[string][fret], &QPushButton::clicked, [this, string, fret]() {
testSlot(string, fret);
});
此代码使用 [captures, ...](arguments, ...) { code }
语法创建一个 lambda。当您建立连接时,它会捕获 string
和 fret
变量值,然后在单击按钮时将它们传递给 testSlot
。
关于c++ - Qt自定义QPushButton点击信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34668541/