Project

General

Profile

Segmentation fault with WStandardItemModel after clear() and setHeaderData()

Added by Richard Bingham over 9 years ago

Hello,

I have a program that's getting a segmentation fault. I've trimmed down the source code a lot and have attached an example program that causes the problem on my system. I was running 3.3.2 when I found the problem, updated to 3.3.3 and the problem still exists.

The trimmed down program is attached.

After adding a WTableView and setting up the header, clear() is called, then when I call setHeaderData() again is when I get the segmentation fault, at line 103.

Any suggestions on what's going on?

Any additional information I should provide to help solve this issue?

Thanks,

Richard.

wtPROB0730.cpp (2.95 KB) wtPROB0730.cpp Source code that shows problem.

Replies (4)

RE: Segmentation fault with WStandardItemModel after clear() and setHeaderData() - Added by Florian Ransmayr over 9 years ago

Hello Richard,

for me it sounds like this issue is connected to this bug: http://redmine.webtoolkit.eu/issues/2408

The "problem" is that you can only set view properties for columns that exists in the model. Here you call clear() that erases all data in the model.

Best Regards

Florian

RE: Segmentation fault with WStandardItemModel after clear() and setHeaderData() - Added by Richard Bingham over 9 years ago

Hi Florian,

Thanks for the reply, however, I'm not sure that applies in this situation since I'm not setting any column properties, other than header contents. I thought the header was a separate object from the columns themselves. Am I wrong in thinking this?

My code for the tableview basically boils down to this:

T = new WTableView();

X->addWidget(T,0,Wt::AlighJustify);

S = new WStandardItemModel(7,7);

S->setHeaderData(0,WString("Name"));

S->setHeaderData(1,WString("QNet"));

T->setModel(S);

S->clear();

S~~setHeaderData(0,WString("Name")); // <---~~ Crashes here.

Thanks,

Richard.

RE: Segmentation fault with WStandardItemModel after clear() and setHeaderData() - Added by Richard Bingham over 9 years ago

Hi again Florian, after reading this again, I'm assuming your saying the clear() not only clears the data from the columns and rows, but also gets rid of all columns and rows and that's what the problem is.

If so, it's very inconsistent. For example, if I remove the line that adds column 1/"QNet", the problem doesn't happen.

It seems like the code should really protect itself with a simple conditional statement or automatically add a new row.

Thanks again for your help,

Richard.

RE: Segmentation fault with WStandardItemModel after clear() and setHeaderData() - Added by Koen Deforche over 9 years ago

Hey,

WStandardItemModel::clear() will remove all data and reset columnCount() and rowCount() to zero. So after a clear you need to insert columns and rows again before you can set data.

I don't see why you find it inconsistent? WStandardItemModel does never add new rows or columns by itself. And it's by the way the same behaviour as Qt's QStandardItemModel.

Regards,

koen

    (1-4/4)