PDA

View Full Version : QStandardItemModel strange behavior with appendColumn



muhzmuhz
28th May 2018, 14:51
Hello guys,

I like to report some strange behavior with QStandardItemModel when using appendColumn.
Here is a quick overview of the circumstances:

I'd like to program a configuration site for IP-Adresses. The configuration site is written in QML, controlled by a C++ class.
The QML page is seperated into two parts, of which one is invisible at a time.
Each part's content will be populated by a QStandardItemModel, where one will be set up at construction time and the second one if something has been clicked on the first (initial visible) part of the page.

Then the second model, where to problem comes up, is set up as follows:



QList<QStandardItem*> itemList;
for (...) {
item->setData(value, roleName);
itemList.pushback(item);
}
model->appendColumn(itemList);
emit modelChanged();


In the QML page, the visibility of the parts are switched, so the content of the second model will be displayed, by a simple Repeater with an ItemDelegate.
But I always get "Unable to assign [undefined] to QString", and this for each entry in the item model.
So I was wondering a bit, because the rowCount seems to be ok. Then I checked the content of the model in the C++ class, everything fine.
My temporary solution was, when I found out the data is actually there, to write a JS function in the QML file, which was called on the modelChanged()-signal.
This function iterates through the item model, and sets up a new ListModel, which I then passed as model to the Repeater - and presto I had my values displayed.
... some days later ...
Today I digged again into this problem and found the solution I was looking for, and it is as simple as confusing:



for (...) {
item->setData(value, roleName);
model->appendRow(item);
}
emit modelChanged();


I just switched from appendColumn with an itemList to appendRow with single items and everything works as intended... hum? :O

Can someone please explain me why there are such differences between this two methods?

Best regards

P.S.: the first model is filled with appendColumn and it works fine there