Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt binary file writing and reading
QtWS25 Last Chance

Qt binary file writing and reading

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seniorc
    wrote on last edited by
    #1

    Hello,
    @void write(QString filename) {
    QChar ch('b');
    QFile mfile(filename);
    if (!mfile.open(QFile::WriteOnly) {
    qDebug() << "Could not open file for writing";
    return;
    }
    QDataStream out(&mfile);
    out.setVersion(QDataStream::Qt_4_8);
    out << ch;
    mfile.close();
    }@
    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";
    return;
    }
    QDataStream in(&mfile);
    in.setVersion(QDataStream::Qt_4_8);
    QChar mT;
    in >> mT;
    qDebug() << mT;
    mfile.close();
    }@
    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved