I have a dialog window which comes up with a list of items in a QListWidget * listWidget.
The Dialog consists of the displayed list and OK/Cancel buttons.
I set the selection to ExtendedSelection and now I can select multiple items from the list.
When a selection is made (signal: itemSelectionChanged) I use:
Qt Code:
  1. QItemSelectionModel * selections = listWidget->selectionModel();
  2. QModelIndexList indexes = selections->selectedIndexes();
To copy to clipboard, switch view to plain text mode 
This code gives me the selected items that I then pass from the dialog (which will be closed) to another function which uses the info and saves the list as integer indexes.
I use integer indexes since I have to use the location in the list for other purposes.

My problems is:
I want to select items in the listWidget when the dialog is opened.
That way, if the user selected items once before, the next time he opens the dialog, the previous selection will be presented for him to change or leave as is.

Should I save the QModelIndexList from before or is there a better way?
e.g what is the right way to select items 2-5,6 in my list?