QTableWidget segmentation fault with setTextAlignment
-
I really hope someone is fixing QTableWidget bugs, because this simply shouldn't happen IMHO:
QModelIndex index = table->model()->index(row, 0); table->model()->setData (index, "?", Qt::DisplayRole); QTableWidgetItem *item = table->item (row, 0); item->setTextAlignment (Qt::AlignRight); ^-- crash hereThe table has 100 rows and 100 columns.
-
@Publicnamer said in QTableWidget segmentation fault with setTextAlignment:
^-- crash here
It should not. What version of Qt are you using? What does
table->model()->setDatareturn? -
I really hope someone is fixing QTableWidget bugs, because this simply shouldn't happen IMHO:
QModelIndex index = table->model()->index(row, 0); table->model()->setData (index, "?", Qt::DisplayRole); QTableWidgetItem *item = table->item (row, 0); item->setTextAlignment (Qt::AlignRight); ^-- crash hereThe table has 100 rows and 100 columns.
@Publicnamer
As @VRonin has asked you.I would assume
QModelIndex index = table->model()->index(row, 0);returns an invalid index if out of range, butQTableWidgetItem *item = table->item (row, 0);would have to return anullptr....Alternatively, you may have a valid
index(row, 0). But that does not mean there is aQTableWidgetItem *itemattable->item (row, 0), cells start out with noQTableWidgetItemin them, you have to put one in, IIRC.Which would explain behaviour you see without there being any " fixing QTableWidget bugs" ?
-
@Publicnamer
As @VRonin has asked you.I would assume
QModelIndex index = table->model()->index(row, 0);returns an invalid index if out of range, butQTableWidgetItem *item = table->item (row, 0);would have to return anullptr....Alternatively, you may have a valid
index(row, 0). But that does not mean there is aQTableWidgetItem *itemattable->item (row, 0), cells start out with noQTableWidgetItemin them, you have to put one in, IIRC.Which would explain behaviour you see without there being any " fixing QTableWidget bugs" ?
-
@JonB said in QTableWidget segmentation fault with setTextAlignment:
you have to put one in
setDataputs the item in so it should be available afterwards@VRonin
[Totally out of my head, not tested.] My understanding was that if you use thesetData()level, that's fine, but I thought that did not create aQTableWidgetItemitem for it.QTableWidgetdoes not reimplementsetData(), so you're saying it would have to do it ondataChanged()signal? (And that doesn't get emitted if you're not actually changing the value.)EDIT OK looked on woboq, agreed, it has internal
QTableModel::setData()which does as you say about creating the item.