Home > Back-end >  Get QListView index is selected
Get QListView index is selected

Time:10-03

Select multiple in the QListView, then I click the button to delete these lines, as follows, in addBtnClicked () I define QItemSelectionModel and QModelIndexList access QListView selected index, but running, can disrupt the end of the function, mainly because QModelIndexList indexlist=selmodel - & gt; SelectedIndexes (); This line defines the cause, could you tell me how to solve it? (my environment is Qt 5.2.0 VS2012 platform, VS2010 V100 toolset, if use V110 tool set is no problem)

Void generalSelectDialog: : addBtnClicked ()
{
QItemSelectionModel * selmodel=UI. List_show - & gt; SelectionModel ();
QModelIndexList indexlist=selmodel - & gt; SelectedIndexes ();
Int count1=indexlist. The size ();
}

Error below

CodePudding user response:

SelectionModel () method returns the value of, can also be null values, so the insurance is at the back of this statement judgment, such as:
 QItemSelectionModel * selmodel=UI. List_show - & gt; SelectionModel (); 
If (selmodel)
{
QModelIndexList indexlist=selmodel - & gt; SelectedIndexes ();
Int count1=indexlist. The size ();
.
}

CodePudding user response:

reference 1st floor ccrun response:
selectionModel method return value, it could also be a null value, so the insurance is at the back of this statement judgment, such as:
 QItemSelectionModel * selmodel=UI. List_show - & gt; SelectionModel (); 
If (selmodel)
{
QModelIndexList indexlist=selmodel - & gt; SelectedIndexes ();
Int count1=indexlist. The size ();
.
}
positive solutions
  • Related