Results 1 to 4 of 4

Thread: Check file if the file is writable or used by another process

  1. #1
    Join Date
    Sep 2011
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Check file if the file is writable or used by another process

    Hello,

    is there a way to check if the file is used by another process like soffice?
    Under Windows it works perfect but under mac/linux is doesnt work. I think mac/linux doesn't make the file only readable.

    My Testcase:

    Qt Code:
    1. QString fileName = childElement.text();
    2. fileName = QDir::tempPath() + "/" + fileName;
    3.  
    4. for(int i=0; i < 100; i++)
    5. {
    6. QFile file(fileName);
    7.  
    8. if(file.open(QIODevice::WriteOnly))
    9. {
    10. qDebug() << "JA";
    11. } else {
    12. qDebug() << "NEIN";
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Check file if the file is writable or used by another process

    Unfortunately there is no file locking in Unix.
    What you can do is call a system command and use a combination of fuser and grep to find if some other process is using the file.

  3. #3
    Join Date
    Sep 2011
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check file if the file is writable or used by another process

    Quote Originally Posted by Charvi View Post
    Unfortunately there is no file locking in Unix.
    What you can do is call a system command and use a combination of fuser and grep to find if some other process is using the file.
    unix create a ".~lock.filename#" logfile. but i have hope there is a better way to handle this. We are open the file with QDesktopService:penUrl(...);

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,366
    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: Check file if the file is writable or used by another process

    Unix doesn't create any lock files. If an application doesn't lock the file for exclusive access (and on Unix applications rarely do that), there is no way of knowing if a file is open other than processing the /proc tree (if it exists and you have access to it).
    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. Check file is in Use
    By sagirahmed in forum Newbie
    Replies: 2
    Last Post: 29th November 2010, 13:51
  2. Check file is modified?
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 6
    Last Post: 20th September 2007, 14:03
  3. How to check a file for changes since last save
    By nmather in forum General Programming
    Replies: 2
    Last Post: 22nd April 2007, 00:43
  4. Check for compressed .qm file?
    By ksierens in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2006, 20:52
  5. Check if a file has been modified
    By Dark_Tower in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 22:27

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
  •  
Qt is a trademark of The Qt Company.