Hi all.

I've been using Qt for a few days now and having trouble populating a QTableWidget with data from an CSV file. My code is as follows:

Input text file:

Qt Code:
  1. Test1
  2. Heyheyhey25
To copy to clipboard, switch view to plain text mode 

Code for inserting the file into QTableWidget:

Qt Code:
  1. {
  2. QFile file("filename");
  3.  
  4. // QString fileName = QFileDialog::getOpenFileName(this, ("Open File"), "/home", ("csv File(*.csv)"));
  5. // QFile file(fileName);
  6.  
  7. QString data;
  8. QStringList rowOfData;
  9. QStringList rowData;
  10. data.clear();
  11. rowOfData.clear();
  12. rowData.clear();
  13.  
  14. if (file.open(QFile::ReadOnly))
  15. {
  16. data = file.readAll();
  17. rowOfData = data.split("\n");
  18. file.close();
  19. }
  20.  
  21. qDebug()<<rowOfData;
  22.  
  23. for (int x = 0; x < rowOfData.size(); x++)
  24. {
  25. rowData = rowOfData.at(x).split(";");
  26. qDebug()<<rowData;
  27. for (int y = 0; y < rowData.size(); y++)
  28. {
  29. ui->tableWidgetScenarios->item(x,y)->setText(rowData[y]);
  30. }
  31. }
  32. }
To copy to clipboard, switch view to plain text mode 

It crashes whenever I try to insert my data into the tablewidget. Here's the debugger output and error message:

Qt Code:
  1. Debugging starts
  2. ("Test1", "Heyheyhey25")
  3. ("Test1")
  4.  
  5. qtablewidget.h:181: error: Exception at 0x646e55e3, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
To copy to clipboard, switch view to plain text mode 

I've tried with multiple files, same result. Do I need to initialize the widget in some way or what am I doing wrong?

Thanks in advance, regards.