Results 1 to 5 of 5

Thread: Writing text file in execlusive mode

  1. #1
    Join Date
    Mar 2010
    Location
    Luxembourg
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Writing text file in execlusive mode

    Hello I want to write a file in Linux/Windows and in the same time of writing I want that nobody can open the file for reading and for writing.

    Qt Code:
    1. QFile file(filename);
    2. file.open(QIODevice::WriteOnly);
    3. ....
    4. file.close();
    To copy to clipboard, switch view to plain text mode 

    With QIODevice::WriteOnly I can open the file with gEdit is that normal?

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Writing text file in execlusive mode

    Since you executed the program, any files created will default to being owned by you. You have permission to read and write your own files. Users tend to get very upset otherwise, when programs litter their system with files that can't be deleted.

    Note that QFile allows you to set a wide range of permissions.

  3. #3
    Join Date
    Mar 2010
    Location
    Luxembourg
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Writing text file in execlusive mode

    But also setting permissions will not help me.
    I launch my qt program which write the file and I can also open it with an other program.

    In Windows you can create a file with execlusiv rights, that's what I want to do with QT

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Writing text file in execlusive mode

    I don't know what 'exclusive rights' are, but someone - usually the owner, sometimes others - will always be able to read/write a file they've created. Any program that creates files in my user space that I am unable to manipulate is a program that will be headed to the trash heap in an instant.

    If you can't set file permissions (and that's what they are) to what you'd like them to be using QFile, make a system call to the Windows API.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Writing text file in execlusive mode

    I think he means a mandatory lock. That's possible for Windows but not for Linux since locking is not mandatory there on most filesystems.

    http://doc.trolltech.com/solutions/4...ockedfile.html
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Writing the text within a text edit to a file
    By Splatify in forum Newbie
    Replies: 4
    Last Post: 23rd February 2011, 22:48
  2. writing to a text-file
    By QtBros61 in forum Newbie
    Replies: 7
    Last Post: 9th April 2010, 11:15
  3. Writing raw bytes as text?
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 18th May 2009, 16:56
  4. problem in writing text with QFile
    By wei243 in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2007, 14:26
  5. Writing Text on a Rectangle!!!
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2006, 10:23

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.