I created a QTreeWidget and assigned a column as a combobox using the code in a function AddRoot shown below:

Qt Code:
  1. combo_box = new QComboBox();
  2. combo_box->addItem("0");
  3. combo_box->addItem("0.5");
  4. combo_box->addItem("1", QVariant(1));
  5. combo_box->addItem("2", 2);
  6. combo_box->addItem("3", 3);
  7. combo_box->addItem("4");
  8. combo_box->addItem("5");
  9. combo_box->addItem("6");
  10. combo_box->addItem("7");
  11. combo_box->addItem("8");
  12. combo_box->addItem("9");
  13. combo_box->addItem("10");
  14. combo_box->addItem("11");
  15. combo_box->addItem("12");
  16. combo_box->addItem("13");
  17. combo_box->addItem("14");
  18. combo_box->addItem("15");
  19. combo_box->addItem("16");
  20.  
  21. connect(combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(planQuantity()));
  22.  
  23. ui->treeWidget->setItemWidget(itm, 7, combo_box);
To copy to clipboard, switch view to plain text mode 

The combobox shows up nicely and I can see the values I set. The signal also works since I get to planQuantity everytime I change a value.

The problem is how to get the value from the QTreeWidget. I have the following code in planQuantity to add up all the values of the comboboxes in the column.

Qt Code:
  1. void PlanDialog::planQuantity()
  2. {
  3. // Calculate the total plan quantity
  4. float quantity = 0.0;
  5. for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
  6. {
  7. QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
  8. quantity += item->text(7).toFloat();
  9. }
  10.  
  11. ui->planQuantityLineEdit->setText(QString("%1").arg(quantity));
  12. }
To copy to clipboard, switch view to plain text mode 

But the result is always 0. Nothing is returned from the item->text(7).toFloat(). 7 is the column where the combobox resides.

Could you please help me identify the problem?

Thanks,

Pericles