Example how to write data to the file:
QDataStream out
(&file
);
// we will serialize the data into the file out <<
QString("the answer is");
// serialize a string out << (qint32)42; // serialize an integer
QFile file("file.dat");
file.open(QIODevice::WriteOnly);
QDataStream out(&file); // we will serialize the data into the file
out << QString("the answer is"); // serialize a string
out << (qint32)42; // serialize an integer
To copy to clipboard, switch view to plain text mode
Read data from the file:
QDataStream in
(&file
);
// read the data serialized from the file qint32 a;
in >> str >> a; // extract "the answer is" and 42
QFile file("file.dat");
file.open(QIODevice::ReadOnly);
QDataStream in(&file); // read the data serialized from the file
QString str;
qint32 a;
in >> str >> a; // extract "the answer is" and 42
To copy to clipboard, switch view to plain text mode
There is also QTextStream class that is more convenient for writing/reading text.
Bookmarks