How to write data to a file in Qt
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QFile, QTextStream,Qstring, Text Label
Created: (07 Jan 2009)
Last edited: vkmunjpara
(17 Sep 2009)
Overview
This code snippet demonstrates File write operation in Qt for S60.
Preconditions
- Install latest Qt for S60 see Qt for S60 - Installation packages
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
Source File
#include <QFile>
#include <QApplication>
#include <QLabel>
#include <QString>
#include <QTextStream>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file("c://out.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << "This file is generated by Qt \n";
file.close();
return app.exec();
}
- Above code will generate the file out.txt into c: of your emulator. You can find it at this path.
- For 5th edtion SDK
C:\S60\devices\S60_5th_Edition_SDK_v0.9\epoc32\winscw\c
- For 3rd edition SDK
C:\Symbian\9.3\S60_3rd_FP2_Beta\epoc32\winscw\c

