Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check if a file is opened by another instance of a QT app
QtWS25 Last Chance

Check if a file is opened by another instance of a QT app

Scheduled Pinned Locked Moved Solved General and Desktop
qfilefileopensavecppqiodevice
3 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • faiszalkhanF Offline
    faiszalkhanF Offline
    faiszalkhan
    wrote on last edited by
    #1

    When I open a file using QFile::open(QIODevice::ReadWrite), I can find out the mode of the file using filetemp.openMode() with the same instance of QFile only. I have observed that this doesn't work with another instance of QFile pointing to the same file. Not a problem, I can work around this.

    My requirement is when I have opened a file in an instance of my app. When I try to open the same file in another instance of the app I should know that the file is already opened. Since it is another instance which means another QFile object, I get the mode as QIODevice::NotOpen which is not the case. I can't seem to find a solution to this. Would appreciate any help.

    Thanks.

    ODБOïO 1 Reply Last reply
    0
    • faiszalkhanF faiszalkhan

      When I open a file using QFile::open(QIODevice::ReadWrite), I can find out the mode of the file using filetemp.openMode() with the same instance of QFile only. I have observed that this doesn't work with another instance of QFile pointing to the same file. Not a problem, I can work around this.

      My requirement is when I have opened a file in an instance of my app. When I try to open the same file in another instance of the app I should know that the file is already opened. Since it is another instance which means another QFile object, I get the mode as QIODevice::NotOpen which is not the case. I can't seem to find a solution to this. Would appreciate any help.

      Thanks.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @faiszalkhan hi,
      Qt has an implementation of LockFile approach.

      faiszalkhanF 1 Reply Last reply
      3
      • ODБOïO ODБOï

        @faiszalkhan hi,
        Qt has an implementation of LockFile approach.

        faiszalkhanF Offline
        faiszalkhanF Offline
        faiszalkhan
        wrote on last edited by
        #3

        @LeLev Thanks, I'll check it out!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved