I wish to print all the items of listwidget in a file. The listwidget is contained in a dialog.

I wanted to access the listwidget items row by row and print the name of items in a file. Kindly suggest some way to do this.

Qt Code:
  1. for(int i=0; i<=listwidget->count(); i++)
  2. {
  3. QString bstr = listwidget->item(i)->text(); // but item() takes only const
  4. spf_in<<bstr<<"\n";
  5.  
  6. }
To copy to clipboard, switch view to plain text mode 

Any help will be appreciated.