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();
{
QString val
= item
->data
(Qt
::DisplayRole).
toString();
if (tag
== QString("Width")) rect.
setWidth(t
);
else rect.setHeight(t);
panel->setRect(rect);
rootItems.at(1)->setData(s, Qt::DisplayRole);
qDebug() << rootItems.at(0)->data(Qt::DisplayRole).toString() << ":" << rootItems.at(1)->data(Qt::DisplayRole).toString();
scene->update();
}
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();
}
To copy to clipboard, switch view to plain text mode
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,
error.png
anyone has suggestion? thanks.
Bookmarks