跨平台开发的时候,经常涉及到路径的表示问题,有单斜杠、双斜杠、双反斜杠等等,很容易出问题,所以直接用separator()方法代替斜杠即可,API原文:

1
2
3
4
5
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().