Question: I've created a checkbox that's also a QTreeWidgetItem using the code below. 

```
//Populate list
QTreeWidgetItem *program = createCheckedTreeItem(QString::fromStdString(itr->first), true);
treePrograms->addTopLevelItem(program);

```

---

```
QTreeWidgetItem* ConfigDialog::createCheckedTreeItem(QString name,bool checkBoxState)
{
  QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
  item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
  if (checkBoxState)
  {
    item->setCheckState(0,Qt::Unchecked);
  }
  else
  {
    item->setCheckState(0,Qt::Checked);
  }
  return item;
}

```

I need a way of connecting a signal and slot for when the state of this checkbox is changed. The current way I've implemented this is below but unfortunately doesn't work. Can someone explain what I'm doing wrong and what I need to do in order to get it to connect?

```
connect(program, SIGNAL(toggled(bool)), this, SLOT(programChecked(bool)));

```

Answer: 
Your `QTreeWidgetItem` is directly linked to your model data, so you should connect to your QTreeWidget's model's `QAbstractItemModel::dataChanged` signal to be notified of the change.
Add this signal to your QTreeWidget object:

```
connect(ui->treeWidget, &QTreeWidget::itemChanged, this, &YourDialog::treeWidgetItemChanged);

```

so you can use this slot to receive the signal:

```
void YourDialog::treeWidgetItemChanged(QTreeWidgetItem *TWI, int column)
{
    //Do some staff
}

```