QDir::separator() 的用途

官方手册:

[static] QChar QDir::separator()

Returns the native directory separator: "/" under Unix and "\" under Windows.

You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators().

See also listSeparator().

[static] QString QDir::toNativeSeparators(const QString &pathName)

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32".

The returned string may be the same as the argument on some operating systems, for example on Unix.

This function was introduced in Qt 4.2.

See also fromNativeSeparators() and separator().

[static] QChar QDir::listSeparator()

Returns the native path list separator: ':' under Unix and ';' under Windows.

This function was introduced in Qt 5.6.

See also separator().

使用 QDir::separator() 的好处:

  • 在表示路径的代码中,允许存在空格;
  • 在跨平台应用场景,不需要自己考虑路径中的 “/” 或 "\" 问题;

  • 在win中,C:/abc/def\ghi   # 同时存在 “/” 和 "\",路径有效;
  • 在linux中,“/”有效, 或 "//"有效。
  • 在linux中表示 win路径, "\\"有效,第一个 "\" 表示转移字符。

结论:"/"  在上述 Linux 和 win平台中通用;其他平台未测试。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值