applicationFilePath() 与 applicationDirPath()的区别

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().

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值