Unsolved 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?
-
@koahnig i use this but its notworking.
give me some another solution. -
@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,
-
@J.Hilk its not working with this.
i opened excel file in ms-excel and i want to check excel file is open or not.
-
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? -
@jsulm yes open manually and want to check for requirement.
-
@Gaurav-Badgujar Do you want to check this in your Qt app?
-
@jsulm yes
-
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 -
You can check if a specific Excel file is open using ActiveQt
get all WorkBooks, iterate over them and check if the name of the workbook you touch corresponds to the one you want.
If that is the case, your excel file is already open. -
@Eddy
That is not a bad idea.
I even think that
ThisWorkbook.FullName
Workbook.FullName
will give full path to file. -
@mrjj
Yes, that is possible, but other files can be open already and the one we want to check is not necessarily the active one.Eddy
-
@Eddy
Oh bad naming. I did mean when he looped over all open.