这个类提供了对 QIODevice 是二进制数据的序列化。以下是官方的例子:
向一个 stream 写入二进制数据
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
file.close();
从一个 stream 中读取二进制数据
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
ui->textBrowser->setText(str + QString::number(a));
显示结果: