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



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



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



  • @LeLev Thanks, I'll check it out!


 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.