Looks like you forget about numbering. It starts from 0. Cheers.
Looks like you forget about numbering. It starts from 0. Cheers.
No, I didn't forget about numbering. If you'll notice, I'm reading cells 0 thru 4 into a stringlist via the foreach statement and cell 5 into a string on it's own right after. That leaves me with cell 6, which is the checkbox that I need to determine the state of. The first code snippet shows that the checkbox is indeed in cell 6.
you have to get cell widget from QTableWidget with QTableWidget::cellWidget() - I wonder how you could miss that method in docs as you found setCellWidget() (cellWidget() is in 'see also' note in description of setCellWidget()). So you can very easily get your checkbox:
Qt Code:
QCheckBox *cb = qobject_cast<QCheckBox *>(m_ui->tableWidget->cellWidget(selected[5]->row(), selected[5]->column()));To copy to clipboard, switch view to plain text mode
So I hope you can now determine the checkstate of that checkbox.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Thanks faldżip,
I did see the cellWidget method, but it wasn't working the way I was using it (which was similar to the line you gave me). That made me think it wasn't the way to access the checkbox. Your line made me look further and this is what I found.
If I use 'selected' to get at the row or column,
Qt Code:
QCheckBox *cb = qobject_cast<QCheckBox *>(m_ui->tableWidget->cellWidget(selected[6]->row(), selected[6]->column()));To copy to clipboard, switch view to plain text mode
the program halts on a signal at that line.
The only way I found that works is to hard code the column in there and use item-row() to get the row:
Qt Code:
To copy to clipboard, switch view to plain text mode
Six is the correct column. There are seven columns in my table.
This is no biggie, as the column that hold the checkbox won't change, but I'd like to know if there's a problem in the way I'm implementing on_tableWidget_itemSelectionChanged that is causing this.
you mean you get segmentation fault? So check which of these many function calls in this line causes this seg fault. What item->column() returns?the program halts on a signal at that line
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Not a segfault, I get this:
Qt Code:
ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qlist.h, line 403To copy to clipboard, switch view to plain text mode
when I try to use sender[6] to get the row and/or column.
This looks to me that ther is no sixth column in the table, but there is. I can force it to get column six by hardcodeing in a 6,
Qt Code:
To copy to clipboard, switch view to plain text mode
but I can't get column six using
Qt Code:
QCheckBox *mcb = qobject_cast<QCheckBox*>(m_ui->tableWidget->cellWidget(item->row(), selected[6]->column()));To copy to clipboard, switch view to plain text mode
Why!?
Had to wrap the Assert in code or the second colon after QList<T> showed up as a smilie..
Bookmarks