一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

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"

 

posted on 2022-05-24 14:24  一杯清酒邀明月  阅读(1064)  评论(0编辑  收藏  举报