How to find the path of the file that launches the Qt application from explorer
-
@JNBarchan said in How to find the path of the file that launches the Qt application from explorer:
So [0] is never to be used. I suspect @sierdzio was intending arguments()[1] maybe.
Yes, my bad, sorry! I've corrected the post.
-
@QtVik said in How to find the path of the file that launches the Qt application from explorer:
@sierdzio @JNBarchan @mrjj :
But this line is causing an assertion failure "index out of range" in qlist.h line#510
qDebug() << "File path:" << args.at(1);Try printing all args:
qDebug() << "File path:" << args;
This will show you all arguments (apart from ones consumed by Qt).
-
@sierdzio
Actually I want path of the file which is invoking my application not the path of my application.exe.Example:
I have a file named "sample.dat" in "C:\Meas folder" and Qt application in "C:\QApplication\Qapp.exe"
Now if I double click on the "sample.dat " I should be able to find this path (C:\Meas folder) through my Qt application ie. Qapp.exeThanks
-
@QtVik said in How to find the path of the file that launches the Qt application from explorer:
Actually I want path of the file which is invoking my application not the path of my application.exe.
I know, that's what we are trying to help you with.
Actually, apart from using QCoreApplication::arguments(), you may also consider using QDir::currentPath().
-
@sierdzio said in How to find the path of the file that launches the Qt application from explorer:
you may also consider using QDir::currentPath().
Do you have any evidence/knowledge that launching by double-clicking from Windows Explorer sets the application's current directory to that of the file double-clicked on??
-
@JNBarchan said in How to find the path of the file that launches the Qt application from explorer:
@sierdzio said in How to find the path of the file that launches the Qt application from explorer:
you may also consider using QDir::currentPath().
Do you have any evidence/knowledge that launching by double-clicking from Windows Explorer sets the application's current directory to that of the file double-clicked on??
Nope, it's just a guess.
-
@JNBarchan
Following are the values for const QStringList args(QApplication::instance()->arguments()), argc ,argv:
1] argc value is 1
2] argv value is the application path .
3] args.at(0) value is also application path .
4] args.at(1) -> crash the application .The above values are shown when I double click on the application directly.
But this is not what i want !
I want path of the file that is trying to invoke my application from explorer.
Example: from the previous post it should be "C:\Meas_folder\sample.dat"Note: I have set my Qapp.exe as default application to open for sample.dat
Thanks
-
@QtVik Please provide same information for the case you are interested in! It doesn't help at all if you double click your app and then post the results here: this is not the use case you're interested in, right?
So, open you app from explorer with a data file and post the content of QApplication::instance()->arguments() here..."Note: I have set my Qapp.exe as default application to open for sample.dat" - then it should be enough to double click on sample.dat and post the output of QApplication::instance() here.