[Qt-interest] Writing file.

Sean Harmer sean.harmer at maps-technology.com
Wed Apr 8 12:35:38 CEST 2009


Hi,

On Wednesday 08 April 2009 11:22:20 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);
>
> QTextStream out(&filewrite);
>
> out << noOfPoints << "\n";
>
> Can anyone please check whats wrong in this why it's not writing the
> data onto the file.
Well for starters you are not checking if the file actually gets opened 
successfully. The QFile::open() function returns a bool for a reason! You may 
not have permissions to create this file for example.

Secondly since you are using a QTextStream on the file I recommend you also 
pass in the QIODevice::Text flag.

See how you get one from here.

Sean




More information about the Qt-interest-old mailing list