sark9012 sark9012 - 4 months ago 32
C++ Question

Attempting to get signal from checkbox change

The following code sets up a list of checkboxes.

QWidget *w = new QWidget(this);
QVBoxLayout *vbox = new QVBoxLayout;

foreach(QString filt, filters){
QCheckBox *checkbox = new QCheckBox(filt, this);

connect(this, SIGNAL(statechanged(int)), this, SLOT(cbstate(int)));



The idea is that when the user checks or unchecks an item, it will emit a signal.

In the header file, I have included the following in the private slots:

void cbsate(int state);

And in the cpp file, I have declared this:

void MainWindow::cbstate(int state){
if(state == 0){
QMessageBox::information(this, "Unchecked", "You have unchecked this box");
else if (state == 2){
QMessageBox::information(this, "Checked", "You have checked this box");

I'm now getting an error of

no 'void MainWindow::cbstate(int)' member function declared in class 'MainWindow'

Any ideas? Am I going about this correctly? Thanks.


It definately sounds as if you have not added the method cbstate to your header file correctly. If you copy and pasted this from your header file, then you have a typo:

void cbsate(int state);

should be:

void cbstate(int state);