Hello,
Qt Code:
  1. void write(QString filename) {
  2. QChar ch('b');
  3. QFile mfile(filename);
  4. if (!mfile.open(QFile::WriteOnly) {
  5. qDebug() << "Could not open file for writing";
  6. return;
  7. }
  8. QDataStream out(&mfile);
  9. out.setVersion(QDataStream::Qt_4_8);
  10. out << ch;
  11. mfile.close();
  12. }
To copy to clipboard, switch view to plain text mode 

open binary file and writing ‘b’(binary)
Qt Code:
  1. void read(QString filename) {
  2. QFile mfile(filename);
  3. if (!mfile.open(QFile::ReadOnly)) {
  4. qDebug() << "Could not open file for reading";
  5. return;
  6. }
  7. QDataStream in(&mfile);
  8. in.setVersion(QDataStream::Qt_4_8);
  9. QChar mT;
  10. in >> mT;
  11. qDebug() << mT;
  12. mfile.close();
  13. }
To copy to clipboard, switch view to plain text mode 

read but not mT=‘b’.if ch and mT variables are int always mT=4 why?How can i writing ch(binary file) and read from binary file
im working huffman encode project.I have all i needs(freq table,char code…)but i was writing code i cant earning size.I think this problem reason is opened binary and writing problem.How can i opened binary file and writing variables bytes.

for example;
Qt Code:
  1. int x=4;
  2. QString abc="hello";
  3. char ch ='a';
To copy to clipboard, switch view to plain text mode 

How can i writing them file.Thanks for all helping now.