Qt binary file writing and reading

  • Hello,
    @void write(QString filename) {
    QChar ch('b');
    QFile mfile(filename);
    if (!mfile.open(QFile::WriteOnly) {
    qDebug() << "Could not open file for writing";
    QDataStream out(&mfile);
    out << ch;
    open binary file and writing 'b'(binary)

    @void read(QString filename) {
    QFile mfile(filename);
    if (!mfile.open(QFile::ReadOnly)) {
    qDebug() << "Could not open file for reading";
    QDataStream in(&mfile);
    QChar mT;
    in >> mT;
    qDebug() << mT;
    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;
    @int x=4;
    QString abc="hello";
    char ch ='a';@
    How can i writing them file.Thanks for all helping now.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.