1./转\(斜杠转反斜杠)函数
[static] QString QDir::toNativeSeparators(const QString &pathName)
2./转\(斜杠转反斜杠)函数
[static] QString QDir::fromNativeSeparators(const QString &pathName)
下面测试典例:
1 //获取应用程序的目录
2 QString strCurrentApplicationDirPath=QCoreApplication::applicationDirPath();
3 qDebug()<<strCurrentApplicationDirPath;
4
5 /*将/转\(斜杠转反斜杠)*/
6 QString strPath=QDir::toNativeSeparators(strCurrentApplicationDirPath);
7 qDebug()<<strPath;
8
9 /*将\转/(反斜杠转斜杠)*/
10 QString strPath2=QDir::fromNativeSeparators(strPath);
11 qDebug()<<strPath2;
调试输出如下:
"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"
"D:\\QT5SourceCode\\build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug\\debug"
"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"