PDA

View Full Version : setData problem at QStandardItemModel first visible item!!!



josentop
10th February 2012, 06:42
Hi,
I have created a QStandardItemModel for QTreeView and will update some item's data when some data changed. Everything is ok except when set data to the first visible item, it will cause the program exit in abnormal. the code as below:


QString tag = tagitem->data(Qt::DisplayRole).toString();
if (tag == QString("Width") || tag == QString("Height"))
{
QString val = item->data(Qt::DisplayRole).toString();
int t = QLocale().toInt(val);
QRectF rect = panel->rect();
if (tag == QString("Width")) rect.setWidth(t);
else rect.setHeight(t);
panel->setRect(rect);

QString s = QLocale().toString(rect.width()) +
QString("x") +
QLocale().toString(rect.height());

rootItems.at(1)->setData(s, Qt::DisplayRole);

qDebug() << rootItems.at(0)->data(Qt::DisplayRole).toString() << ":" << rootItems.at(1)->data(Qt::DisplayRole).toString();
scene->update();
}


I just want to update the panel data (1920x1080) according panel's width or height change. I'm sure rootItems.at(1) is pointed to the data (1920x1080), please see below picture,
7396

anyone has suggestion? thanks.

ChrisW67
10th February 2012, 07:01
Which line causes the crash? Your debugger will tell you. Without that information I would guess: one or more of the tagItem, item, panel, scene, or rootItems.at(0 or 1) pointers are null or invalid. Possibly rootItems contains less than two entries, which would also be a bad thing.

josentop
11th February 2012, 00:28
Thanks for reply. The crash caused by line 15, but I'm sure rootItems contains 2 entries because if I remove line 15, line 16 can work well and output follow message:
"Panel" : "1920x1080"
It means rootItems.at(1) has the initial data "1920x1080". Please help to analysis again, thanks.