以下代码设置复选框列表。
QWidget *w = new QWidget(this);
w->setFixedSize(300,200);
QVBoxLayout *vbox = new QVBoxLayout;
foreach(QString filt, filters){
QCheckBox *checkbox = new QCheckBox(filt, this);
checkbox->setChecked(true);
vbox->addWidget(checkbox);
connect(this, SIGNAL(statechanged(int)), this, SLOT(cbstate(int)));
}
w->setLayout(vbox);
w->show();
这个想法是,当用户选中或取消选中一个项目时,它会发出一个信号。
在头文件中,我在私有插槽中包含以下内容:
void cbsate(int state);
在 cpp 文件中,我声明了这一点:
void MainWindow::cbstate(int state){
if(state == 0){
//unchecked
QMessageBox::information(this, "Unchecked", "You have unchecked this box");
}
else if (state == 2){
//checked
QMessageBox::information(this, "Checked", "You have checked this box");
}
}
我现在收到一个错误
没有在类“MainWindow”中声明的“void MainWindow::cbstate(int)”成员函数
有任何想法吗?我这样做对吗?谢谢。