title: How to fix QFile open error (unknown error) even the file exists?
body: <p>I am new to C++ and Qt. I am trying to open and read a map.dat file using QFile interface, but it won't open that file even it does exist in the directory.</p>
  
  <ol>
  <li>I have tried fopen, ifstream in C++, but they keep telling me the file does not exist even I have added it into resource folder (.qrc). Then I turn to QFile interface, the problem remains. This is a directory problem, I now compromise and use absolute(not the best practice) path and now the file existence problem is solved.</li>
  <li>Now it still cannot open the file, I use interface's member function to see what are the error code and error message, and I got 0 and "Unkown Error" which is so frustrating as they don't give me any useful information.</li>
  <li><p>I am using MacOS Mojave 10.14.2. Qt 5.11.3. Compiler is Qt 5.11.3 clang_64bit</p>
  
  <pre><code>QFile mapDat("/Users/myname/projectname/file.dat");
   if (!mapDat.exists()){
       qDebug() &lt;&lt; "not exist";
   }
   QString errMsg;
   QFileDevice::FileError err = QFileDevice::NoError;
   if (!mapDat.open(QIODevice::ReadOnly) | QFile::Text){
       errMsg = mapDat.errorString();
       err = mapDat.error();
       qDebug() &lt;&lt; "could not open it" &lt;&lt; err &lt;&lt; errMsg;
       return;
   }
   QTextStream in(&amp;mapDat);
   QString mText = in.readAll();
   qDebug() &lt;&lt; mText;
   mapDat.close();
  </code></pre></li>
  </ol>
  
  <p>I am rather new to C++, but I expect the <code>qDebug() &lt;&lt; mText</code> to give me something in the console, but it doesn't. The output is 
  <code>could not open it 0 "Unknown error"</code>, which is from the <code>qDebug()</code> line within the if statement.</p>