我似乎无法将参数传递给插槽。如果我不传递参数,该函数将正常运行。如果我传递一个参数(整数),我会在编译时收到错误“No such name type”和“No such slot”。
在我的标题中,我声明:
private slots:
void addButton(int);
signals:
void clicked(int)
在我的 Main.cpp 中,我这样做:
int count;
int count = 0;
QPushButton* button = new QPushButton("Button");
_layout->addWidget(button);
connect(button, SIGNAL(clicked(count), this, SLOT(addButton(count)));
....
void Main::addButton(int count) {
//do stuff with count
}
最佳答案
Sebastian 是正确的,您不能以您尝试的方式执行此操作,但是 Qt 确实提供了一个类,可以为您提供所需的功能。
查看 QSignalMapper .它允许您将整数与对象/信号对相关联。然后你连接到它的信号而不是直接连接到按钮。
关于c++ - Qt问题将参数传递给插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160321/