Hi,

i got a file which holds some lines like this:

19,sunshine live,0x1234
19,radio bob, 0xabcd
19,sputnik,0x1a2b

and so on..

My program reads this file and my goal is to output only the station name (2 entry in each line) in a QListWidget. Anyway the other 2 entries in each line should be hold in a vector or array, to use them later.

So far I got this, but it doesn't work right:

Qt Code:
  1. void MainWindow::on_pushButton_clicked()
  2. {
  3. QFile file(pfad);
  4. if(!file.open(QFile::ReadOnly | QFile::Text)){
  5. QMessageBox::warning(this,"..","keine datei gefunden");
  6. return;
  7. }
  8.  
  9. QTextStream in_file(&file);
  10. QString text;
  11.  
  12. QVector<QVector<QString> > vectorOfVectorsOfStrings;
  13. QVector<QString> zeile;
  14.  
  15. while (!in_file.atEnd()) {
  16. text = in_file.readLine();
  17. QStringList split_text = text.split(",");
  18.  
  19. for (int i = 0; i < 3; i++){
  20.  
  21. zeile.push_back(split_text.at(i));
  22. vectorOfVectorsOfStrings.push_back(zeile);
  23. }
  24. }
  25.  
  26. file.close();
  27.  
  28. for(int i = 0; i < vectorOfVectorsOfStrings.size(); i++)
  29. {
  30. for(int j = 0; j < vectorOfVectorsOfStrings[i].size(); j++)
  31. {
  32. ui->listWidget->addItem(vectorOfVectorsOfStrings[i][1]);
  33. }
  34. }
  35. }
To copy to clipboard, switch view to plain text mode 

The program is crashing with message [i] out of range. So i tried to set a fixed value just to so the output, and then my ListWidget was showing several times sunshine live. I guess the error is somewhere in here:

Qt Code:
  1. while (!in_file.atEnd()) {
  2. text = in_file.readLine();
  3. QStringList split_text = text.split(",");
  4.  
  5. for (int i = 0; i < 3; i++){
  6.  
  7. zeile.push_back(split_text.at(i));
  8. vectorOfVectorsOfStrings.push_back(zeile);
  9. }
  10. }
To copy to clipboard, switch view to plain text mode