Check file is open or not
-
Hi,
I Opened some file from local machine and want to check that file is open or not.
How i can achieve this with coding.Regards,
Gaurav Badgujar. -
There are a couple of different ways to open a file. Therefore, it is helpful which you are using?
-
@Gaurav-Badgujar
try#include<QFile> #include<QDebug> QFile file(pathToFile); if(!file.open(QIODevice::readonly){ qDebug() << "File not open" << file.error(); }else{ qDebug() << "File is open"; }
that should tell you why Qfile could not open the file.
-
@Gaurav-Badgujar What is not working? QFile is the most simple way in Qt to open a file. Just saying "its not working" is not very helpful.
-
@Gaurav-Badgujar
can u post the code which u have tried.what is the return value u are getting?.
Thanks,
-
u may look into the below link
https://forum.qt.io/topic/51169/how-to-check-whether-file-already-open-or-not-in-qt
i hope this is what ur topic says.
Thanks,
-
@Pradeep-Kumar yup .. but i want solution.
-
@Gaurav-Badgujar said in Check file is open or not:
i opened excel file in ms-excel and i want to check excel file is open or not.
What? You open an Excel file in Excel and then you want to check whether Excel opened the file?
Do you open this Excel file manually or from your Qt app? Why do you want to check this? -
@Gaurav-Badgujar Do you want to check this in your Qt app?
-
There is no Qt way of doing this.
Its pr. operating system and you will need to use native API to do it.for windows
https://stackoverflow.com/questions/1951791/how-to-check-if-a-file-is-already-open-by-another-process-in-c