Hi, I need to write some text to a file and i am trying to use QFile however i have a few problems, first i thought it was my code so i created a new project with just the example given in the QT documentation and i cant even get that to work! So using the example (where i replace out.txt with D://out.txt to write to my D drive):

Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include<QTextStream>
  3. #include<QFile>
  4.  
  5. int main()
  6. {
  7. QFile file("D://out.txt");
  8. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  9. return;
  10.  
  11. QTextStream out(&file);
  12. out << "The magic number is: " << 49 << "\n";
  13. }
To copy to clipboard, switch view to plain text mode 

first I get the error:

..\filewrite\main.cpp:10: error: return-statement with no value, in function returning 'int'

If i comment out the if statement it runs but i don't create a file. i thought maybe i need to close the file first so i added file.close but that didn't do anything either.

Can someone please help!

Thanks

Matt