Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to perform file IO using QDataStream in Qt

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to use QDataStream for performing file read and write in Qt.

Article Metadata
Tested with
Devices(s): Emulator
Platform(s): Qt
Platform Security
Signing Required: Self-Signed
Capabilities: None
Keywords: QDataStream
Created: james1980 (27 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

Various Functions

  • Sets the serialization byte order to bo.
  • Sets the version number of the data serialization format to v
QDataStream out(file);

Source File

More About QDataStream:

#include "fileIO.h"
#include <QFile>
#include <QLabel>
#include <QDataStream>
fileIO::fileIO(QWidget *parent)
: QWidget(parent)
QFile file("c://test.txt");;
QDataStream out(&file); // we will serialize the data into the file
out << "welcome to the Qt World"; // serialize a string
QFile read("c://test.txt");;
QDataStream in(&read); // read the data serialized from the file
QString str;
in >> str;
This page was last modified on 11 October 2012, at 01:17.
319 page views in the last 30 days.