I guess I figured it out why this crashed: The callback updateStatus which was implemented as partially shown below, was still accessing items if they didn't even exist:
{
if (item && item == currentItem()) {
lastColumn = currentColumn();
lastLine = currentRow();
validSelection=true; // <----- prevents access of garbage later
if (lastColumn == SPCOL::lesseme || lastColumn == SPCOL::promptname) {
emit customSignalEdit( item->data(Qt::StatusTipRole).toString() );
}
}
if (!item || !validSelection) return; // <--- that fixed it
....
// remark: lastColumn and lastLine, as well as validSelection are protected variables in this class, which is derived from QTableWidget ()
void SpreadSheet::updateStatus(QTableWidgetItem *item)
{
if (item && item == currentItem()) {
lastColumn = currentColumn();
lastLine = currentRow();
validSelection=true; // <----- prevents access of garbage later
if (lastColumn == SPCOL::lesseme || lastColumn == SPCOL::promptname) {
emit customSignalEdit( item->data(Qt::StatusTipRole).toString() );
}
}
if (!item || !validSelection) return; // <--- that fixed it
....
// remark: lastColumn and lastLine, as well as validSelection are protected variables in this class, which is derived from QTableWidget ()
To copy to clipboard, switch view to plain text mode
Initially, calling the above with *item == NULL was not properly checked. It turned out that when a new table was displayed updateStatus was also called, even though nothing was selected.
However, just below the code shown here, I accessed the pointer *item without further checking. In that code the assumption was made that previously something had been selected. But that could not be the case for a new table, because I had forgotten to initialize properly some other variables when a new table was loaded.
At any rate, all's working now - you may move to other problems :-) - thanks to anyone who may have wasted any thoughts on this
Bookmarks