How to perform file IO using QDataStream in Qt
Jump to navigation
Jump to search
Various Functions[edit | edit source]
- Sets the serialization byte order to bo.
in.setByteOrder(QDataStream::LittleEndian);
- Sets the version number of the data serialization format to v
QDataStream out(file); out.setVersion(QDataStream::Qt_4_0);
Source File[edit | edit source]
More About QDataStream: http://pepper.troll.no/s60prereleases/doc/qdatastream.html
- include "fileIO.h"
- include <QFile>
- include <QLabel>
- include <QDataStream>
fileIO::fileIO(QWidget *parent)
: QWidget(parent)
{
QFile file("c://test.txt");
file.open(QIODevice::WriteOnly);
QDataStream out(&file); // we will serialize the data into the file
out << "welcome to the Qt World"; // serialize a string
file.close();
QFile read("c://test.txt");
read.open(QIODevice::ReadOnly);
QDataStream in(&read); // read the data serialized from the file
QString str;
in >> str;
}
fileIO::~fileIO()
{
}