×
Namespaces

Variants
Actions

How to perform file IO using QDataStream in Qt

From Nokia Developer 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
Compatibility
Platform(s): Qt
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QDataStream
Created: james1980 (27 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

Various Functions

  • 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

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()
{
 
}
This page was last modified on 11 October 2012, at 01:17.
221 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×