I am having problems encoding a file to base64.

I want to send a pdf by mail so i have to encode it to base64

When i do this:
Qt Code:
  1. QString data;
  2. QFile file(filename);
  3. file.open(QIODevice::ReadOnly | QIODevice::Text);
  4.  
  5. while (!file.atEnd())
  6. {
  7. QByteArray line = file.readLine();
  8. data += line.toBase64();
  9. }
To copy to clipboard, switch view to plain text mode 

The string data seems to content all the information, but if i attached it into a mail i could not open the file

I hope you could help me

Sorry for my bad english