Bug #2408
closedWTreeView, WTableView could trigger application crash with empty WStandardItemModel
0%
Description
Once you specify the width of a colum in a WTreeView or WTableView it is not possible to use a empty model because this will trigger a application crash inside the WStandardItemModel.
In my attached example with the lines you see below it will crash. If the lines are commented everything works.
tv->setColumnWidth(0, Wt::WLength(240));
...
trv->setColumnWidth(0, Wt::WLength(240));
I changed two methods inside the WStandardItemModel to fix this issue but I am not Sure if this is sufficient/a complete solution. Maybe I am wrong to customize a view like this but I thought it should work like this. Please correct me if I am doing something completely wrong here ;)
boost::any WStandardItemModel::headerData(int section, Orientation orientation,
int role) const
{
if (role == LevelRole)
return 0;
std::vector<HeaderData> header
= (orientation == Horizontal) ? columnHeaderData_ : rowHeaderData_;
if(header.size() <= section)
return boost::any();
const HeaderData& d = header[section];
HeaderData::const_iterator i = d.find(role);
if (i != d.end()) {
/*
* Work around CLang bug, 'return i->second' would try to create
* a boost::any<const boost::any> ... ?
*/
boost::any result = i->second;
return result;
} else
return boost::any();
}
WFlags<HeaderFlag> WStandardItemModel::headerFlags(int section,
Orientation orientation)
const
{
const std::vector<WFlags<HeaderFlag> >& fl
= (orientation == Horizontal) ? columnHeaderFlags_ : rowHeaderFlags_;
if(fl.size() > section)
return fl[section];
else
return WFlags<HeaderFlag>();
}
I attached my changed version of the WStandardItemModel based on the current git.
Best Regards
Florian
Files
Updated by Koen Deforche about 11 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
Hey,
You can only set view properties of columns that actually exist in the model.
Perhaps this simply needs to be clarified in the documentaiton?
Regards,
koen
Updated by Florian Ransmayr about 11 years ago
Hi Koen,
thanks for your reply.
To be honest in my opinion it should be possible to customize a WTreeView even if the column doesn't exist at the moment. If no data available it is not necessary to display anything => ignore the customization of the view but don't crash ;). In Qt this is possible.
In my application I need to display a TreeView and for some reasons sometimes there are no items in it at the moment. In my opinion it is not really nice to check for the existence of a column manually to customize the view. The model view concept is to really handle the view independently of the underlying data/model.
In my opinion this is a bug in WStandardItemModel and it shouldn't crash the application. If you think it is sufficient to just mention that in the documentation you can do that as well.
Best regards
Florian
Updated by Florian Ransmayr over 10 years ago
Hey Koen,
for me it sounds that another user had a similar problem that is maybe connected to this issue. see: http://redmine.webtoolkit.eu/boards/2/topics/9405
Best regards
Florian
Updated by Koen Deforche about 10 years ago
- Status changed from Feedback to InProgress
- Target version set to 3.3.4
Updated by Koen Deforche about 10 years ago
- Status changed from InProgress to Resolved
Updated by Koen Deforche almost 10 years ago
- Status changed from Resolved to Closed