QCoreApplication::applicationFilePath(); :给出了可执行文件的目录 和文件名。
注:Qt5. 当没有指定文件名时,applicationFilePath() 返回的是将工程目录名当成文件名,从而造成错误。?
QCoreApplication::applicationDirPath(); :给出了可执行文件的目录。
1 .获取应用程序可执行文件所在的目录: QCoreApplication::applicationDirPath();
QString applicationDirPath;
applicationDirPath = QCoreApplication::applicationDirPath();
qDebug()<<"applicationDirPath"<<applicationDirPath;
2.获取应用程序可执行文件的文件路径: QCoreApplication::applicationFilePath();
QString applicationFilePath;
applicationFilePath = QCoreApplication::applicationFilePath();
qDebug()<<"applicationFilePath"<<applicationFilePath;
[static] QString QCoreApplication::applicationDirPath()
Returns the directory that contains the application executable.
For example, if you have installed Qt in the C:\Qt directory, and you run the regexp example, this function will return "C:/Qt/examples/tools/regexp".
On macOS and iOS this will point to the directory actually containing the executable, which may be inside an application bundle (if the application is bundled).
Warning: On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.
See also applicationFilePath().
[static] QString QCoreApplication::applicationFilePath()
Returns the file path of the application executable.
For example, if you have installed Qt in the /usr/local/qt directory, and you run the regexp example, this function will return "/usr/local/qt/examples/tools/regexp/regexp".
Warning: On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.
See also applicationDirPath().