PDA

View Full Version : file.open( IO_ReadOnly )



Mariane
7th February 2006, 17:54
I'm puzzled by that IO_ReadOnly, I've even seen an example with
my_file.open(IO_WriteOnly | IO_ReadOnly);

If I want to open a file, read something from it, then save to it, with the
stuff being saved being larger than what was originally in the file, how
should I do it?

Mariane

high_flyer
7th February 2006, 18:05
I'm puzzled by that IO_ReadOnly, I've even seen an example with
my_file.open(IO_WriteOnly | IO_ReadOnly);
Thats because you can only have one of the above states.
When you open a file as read only, you wont be able to save in to it, untill you close it, and reopen it with a write access, thats why its called IO_ReadOnly
The same is with the oposite.
If you open a file as write only, you will be only able to write in to it.
If you want to read it, you will have to open it with a read access.
There are IO access modes that allow both reading and writing, appending, etc...

yop
7th February 2006, 19:38
I'm puzzled by that IO_ReadOnly, I've even seen an example with
my_file.open(IO_WriteOnly | IO_ReadOnly);

If I want to open a file, read something from it, then save to it, with the
stuff being saved being larger than what was originally in the file, how
should I do it?

Mariane
The modes for opening files can be ORed together. That means that my_file.open(IO_WriteOnly | IO_ReadOnly); will open the file and you will be able to read the contents. When you write to that file the old contents are deleted and the data you write to that file replace them. If you want to keep your old data you should use IO_Append. Above all you should take a look here (http://doc.trolltech.com/3.3/qfile.html)

Mariane
7th February 2006, 19:55
Thank you.

Mariane