Deleting rows from WTable?
Added by Gunnar Skogsholm over 3 years ago
I can't figure out how to delete rows from a grid. I'm trying:
auto GridRows = gridCtl->rowCount();
for( int c = NumRecords + 1; c < GridRows; c++ )
{
auto row = gridCtl->removeRow( c );
row.reset();
}
Where gridCtl = Wt::WTable*
terminate called after throwing an instance of 'std::logic_error'
what(): WWidget::removeWidget() ought not to be called
Replies (10)
RE: Deleting rows from WTable? - Added by Korneel Dumon over 3 years ago
Hey Gunnar,
I don't immediately see anything wrong. Do you have a stack trace for that exception?
RE: Deleting rows from WTable? - Added by Gunnar Skogsholm over 3 years ago
It does not crash while I step over these lines in the debugger. However, no changes occur. The error message above about removeWidget happens when I stop the application in the debugger.
RE: Deleting rows from WTable? - Added by Gunnar Skogsholm over 3 years ago
Sorry, not when I exit, but after selecting run in the debugger. See image for call stack.
Capture.PNG (151 KB) Capture.PNG |
RE: Deleting rows from WTable? - Added by Korneel Dumon over 3 years ago
This might be a Wt bug. I tried reproducing but it works for me. Which version of Wt are you using?
If you could make a small example that would be very helpful.
RE: Deleting rows from WTable? - Added by Gunnar Skogsholm over 3 years ago
Yuck. What about deleting the cells before deleting the row?
RE: Deleting rows from WTable? - Added by Gunnar Skogsholm over 3 years ago
I'm wondering if it has something to do with adding a TextArea to a Cell:
auto tableCell = gridCtl->elementAt( Rec + NumHdrRows, left() ); // triggers WebTable::createCell
if( tableCell->count() )
editWnd = dynamic_cast<Wt::WTextArea*>(tableCell->widget( 0 ));
else
{
editWnd = tableCell->addWidget(make_unique<Wt::WTextArea>(fieldData->string_value()));
Cells.push_back( editWnd );
}
I'm not sure if this is a normal approach.
RE: Deleting rows from WTable? - Added by Korneel Dumon over 3 years ago
The code looks fine to me.
I just did some more testing and was surprised to see I get this exception also if I remove past the rowCount(), probably due to undefined behavior.
From your example it doesn't look like you are doing this, but it might still be worth checking for memory errors (eg with valgrind).
RE: Deleting rows from WTable? - Added by Gunnar Skogsholm over 3 years ago
Maybe I need to remove from end? If rowCount is adjusted with every removeRow (which makes sense), then I'm doing this wrong.
RE: Deleting rows from WTable? - Added by Korneel Dumon over 3 years ago
Ah yes, now I see it too, you keep using the old rowCount(). Not a Wt bug after all :)