Check file is open or not
-
wrote on 20 Jun 2017, 10:47 last edited by
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. -
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.wrote on 20 Jun 2017, 10:52 last edited byThere are a couple of different ways to open a file. Therefore, it is helpful which you are using?
-
There are a couple of different ways to open a file. Therefore, it is helpful which you are using?
wrote on 20 Jun 2017, 10:53 last edited by@koahnig i use this but its notworking.
give me some another solution. -
@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.
-
@koahnig i use this but its notworking.
give me some another solution.@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.
-
wrote on 20 Jun 2017, 11:05 last edited by
@Gaurav-Badgujar
can u post the code which u have tried.what is the return value u are getting?.
Thanks,
-
@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.
wrote on 20 Jun 2017, 11:07 last edited by@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.
-
wrote on 20 Jun 2017, 11:21 last edited by Pradeep Kumar
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,
-
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,
wrote on 20 Jun 2017, 11:23 last edited by@Pradeep-Kumar yup .. but i want solution.
-
@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.
@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 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?wrote on 20 Jun 2017, 12:32 last edited by@jsulm yes open manually and want to check for requirement.
-
@jsulm yes open manually and want to check for requirement.
@Gaurav-Badgujar Do you want to check this in your Qt app?
-
@Gaurav-Badgujar Do you want to check this in your Qt app?
wrote on 20 Jun 2017, 12:39 last edited by@jsulm yes
-
@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 -
wrote on 20 Jun 2017, 17:42 last edited by
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. -
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.
1/18