Results 1 to 4 of 4

Thread: file.open( IO_ReadOnly )

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default file.open( IO_ReadOnly )

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: file.open( IO_ReadOnly )

    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...

  3. #3
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file.open( IO_ReadOnly )

    Quote Originally Posted by Mariane
    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

  4. #4
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: file.open( IO_ReadOnly )

    Thank you.

    Mariane

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.