[Qt-interest] Writing file.
Yves Bailly
yves.bailly at sescoi.fr
Wed Apr 8 12:34:19 CEST 2009
Hello,
Sujan Dasmahapatra wrote:
> Dear Friends I am writing some data in file which doesn’t exist.So I
> think it should be created and then being written but it’s not writing
> the data onto the file.Can u please anyone check whats wrong with this
> piece of code !!!
>
> QFile filewrite(“profile_n.grd”);
> filewrite.open(QIODevice::WriteOnly);
Better check if the open succeded:
if ( filewrite.open(QIODevice::WriteOnly)
{
// writing
}
else
{
// error management,
// see QFile::error()
}
> QTextStream out(&filewrite);
> out << noOfPoints << “\n”;
Maybe, close the file. The whole code would be:
QFile filewrite(“profile_n.grd”);
if ( filewrite.open(QIODevice::WriteOnly)
{
QTextStream out(&filewrite);
out << noOfPoints << “\n”;
out.flush(); // probably not necessary...
filewrite.close();
}
else
{
// error management,
// see QFile::error()
}
If that doesn't work, check if you have write permission on
the directory where the file is to be created.
Hope this helps.
--
/- Yves Bailly - Software developper -\
\- Sescoi France http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."
More information about the Qt-interest-old
mailing list