title: How to get the text of selected item from QListView in QT?
body: <p>I need to get the selected item name in <code>QListView</code> as a <code>QString</code>. I have tried to google, but I have not found anything useful.</p>
  
  <p>My <code>QListView</code>, <code>Model</code> and the method to populate it is as follow:</p>
  
  <pre><code>QString setting_path = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
  
  QStandardItemModel *model2=new QStandardItemModel();
  
  QFile file(setting_path+"history.txt");
  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
      return;
  
  QTextStream in(&amp;file);
  
  while(!in.atEnd()) {
  QString line = in.readLine();
  QList&lt;QStandardItem *&gt; items;
  QStringList fields = line.split("&gt;");
  QStringList fields3 = fields.filter("");
  
  foreach (QString text, fields3)
  {
      items.append(new QStandardItem((QString)text));
  }
  
  if(items.length() &gt; 0)
  {
      model2-&gt;appendRow(items);
  }
  }
   ui-&gt;listView-&gt;setModel(model2);
  }
  </code></pre>