Hi ,

In my example I use a model/view. My class is QSqlTableModel for the model and QTableView for the view.
I know save data to a file (.txt and even .csv if I wish).

Qt Code:
  1. void Data_Example::txtExport()
  2. {
  3.  
  4. QString fileName = QFileDialog::getSaveFileName(this,
  5. tr("Save"), "",
  6. tr("Save (*.txt);;All Files (*)"));
  7.  
  8. if (fileName.isEmpty())
  9. return;
  10. else {
  11. QFile file(fileName);
  12. if (!file.open((QIODevice::WriteOnly) | QIODevice::Text))
  13. {
  14. QMessageBox::information(this, tr("Unable to open file"),
  15. file.errorString());
  16. return;
  17. }
  18.  
  19. QString data;
  20. data ="";
  21.  
  22. for (int row = 0; row < model->rowCount(); ++row)
  23. {
  24. QSqlRecord record = model->record(row);
  25. for (int field = 0; field < record.count(); ++field)
  26. {
  27. if(field != 0 && field !=4 )
  28. {
  29. if (field > 1) data += "\n";
  30.  
  31. data += record.field(field).value().toString();
  32.  
  33. }
  34. }
  35. }
  36.  
  37. QTextStream output(&file);
  38. output.setCodec("UTF-8");
  39. output << data;
  40.  
  41. }
To copy to clipboard, switch view to plain text mode 

And in my file (.txt) I have for instance:

Alicia
Tucker
21/09/1985

John
Smith
18/02/1964

Jessica
Houston
07/11/1993
Now, I search to load this file or an other file like this but I don't find solutions...
I start to write this:

void Data_Example::txtImport()
{

QString fileName = QFileDialog::getOpenFileName(this,
tr("Open My File"), "",
tr("My File (*.txt);;All Files (*)"));

if (fileName.isEmpty())
return;
else
{
QFile file(fileName);

if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}

QTextStream input(&file);
QString line;
do
{
input >> data;
line = input.readLine();
} while(!line.isNull());
//file.close();


}
}
This part doesn't function because I don't have a loop which load data in my QslqTableModel.
If somebody know...

Thanks.