Hello
So i'm trying to read from a .txt file when the application is closed or when the user presses the X button on the top right corner.

I tried reading from a file that is already created, but for some reason it's not opening the file, it always prints out "doesn't exist".

Qt Code:
  1. void Game::closeEvent(QCloseEvent *event)
  2. {
  3. QString item;
  4. /*
  5.   QFile inputFile("Save.txt");
  6.   if (inputFile.open(QIODevice::ReadOnly))
  7.   {
  8.   QTextStream in(&inputFile);
  9.   while (!in.atEnd())
  10.   {
  11.   item = in.readLine();
  12.   qDebug() << item;
  13.   }
  14.   inputFile.close();
  15.   }
  16. */
  17. fstream myFile("Save.txt", ios::in);
  18. string line;
  19.  
  20. //myFile.open("Save.txt");
  21. if(myFile.is_open()){
  22. while(getline(myFile,line)){
  23. qDebug() << QString::fromStdString(line);
  24. }
  25.  
  26. }else{
  27. qDebug() << "doesnt exist";
  28. }
  29. myFile.close();
  30. qDebug() << "closed";
  31. }
To copy to clipboard, switch view to plain text mode 

I included <fstream>
and added using namespace std;
The file exists in the file and it contains 3 lines and each one of them has a string
And i tried both examples, using fstream and using QFile ( none of them work )

If anyone knows what could be the problem please help me out !