There are no trivial things in work: turning a stone into gold and a drop into a river. Only by taking everything you do seriously can you overcome all difficulties and achieve success.
The program crashed when using QT’s qitemselectionmodel to get qmodelindexlist in the project.
Usage scenario:
QItemSelectionModel *selections =pTreeView->selectionModel(); QModelIndexList selectedindexes = selections->selectedRows();
In this way, an error will be reported after calling.
Solution: find the source code of selectedrows and implement the currently selected item by yourself
QItemSelectionModel *selections = pTreeView->selectionModel(); QModelIndexList selectedindexes; //the QSet contains pairs of parent modelIndex //and row number QSet<QPair<QModelIndex, int>> rowsSeen; const QItemSelection ranges = selections->selection(); for (int i = 0; i < ranges.count(); ++i) { const QItemSelectionRange& range = ranges.at(i); QModelIndex parent = range.parent(); for (int row = 0; i < range.top(); row <= range.bottom(); row++) { QPair<QModelIndex, int> rowDef = qMakePair(parent, row); if (!rowsSeen.contains(rowDef)) { rowsSeen << rowDef; if (selections->isRowSelected(row, parent)) { selectedindexes.append(pModel->index(row, 0, parent)); } } } }
Similar Posts:
- [Solved] Operator overload must take either zero or one argument error
- TypeError: ‘list’ object cannot be interpreted as an integer
- [swscaler @ …] deprecated pixel format used, make sure you did set range correctly
- Error:This Activity already has an action bar supplied by the window decor.
- Vue3 vue.draggable slot jsx Error: Error: draggable element must have an item slot
- How to Solve Error: Cannot read property ‘map’ of undefined
- [Solved] error: resource style/AppTheme (aka com.example.myapplication:style/AppTheme
- [Solved] Error: error c2678: binary ‘<', no left operand operator (or no acceptable conversion) that accepts type 'const a' was found
- Python scrapy/ ERROR: Spider must return request, item, or None, got ‘Tag ‘insettlement program