PDA

View Full Version : File Handling!!!



mebingj
26th January 2011, 19:37
I cannot write to the file and read from it
here is my code..

write:


QFile file("dd.txt");
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out<<d;
file.close();


read:


QFile f("dd.txt");
f.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream stream(&f);
l=stream.readLine();
f.close();

Lykurg
26th January 2011, 19:49
Please notice the [code] tags, and what returns open()? Or errorString()?

squidge
26th January 2011, 20:14
"cannot write to the file and read from it" is too ambigous. The file is not created? The file is empty? The file was written but you can't read?

As already stated, please add error checking into your code and tell us exactly what happens.

ChrisW67
26th January 2011, 21:32
The program will attempt to create this file in its working directory. Often that is a non-writeable location (e.g. "C:\Program Files\Your Program" on Windows).