1./转\(斜杠转反斜杠)函数
[static] QString QDir::toNativeSeparators(const QString &pathName)
2./转\(斜杠转反斜杠)函数
[static] QString QDir::fromNativeSeparators(const QString &pathName)
下面测试典例:
//获取应用程序的目录
QString strCurrentApplicationDirPath=QCoreApplication::applicationDirPath();
qDebug()<<strCurrentApplicationDirPath;
/*将/转\(斜杠转反斜杠)*/
QString strPath=QDir::toNativeSeparators(strCurrentApplicationDirPath);
qDebug()<<strPath;
/*将\转/(反斜杠转斜杠)*/
QString strPath2=QDir::fromNativeSeparators(strPath);
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"