其他分享
首页 > 其他分享> > Qt 快速转换路径(/斜杠与\反斜杠转换)

Qt 快速转换路径(/斜杠与\反斜杠转换)

作者:互联网

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"

 

标签:转换,Qt,QT5SourceCode,build,斜杠,debug,QString
来源: https://www.cnblogs.com/ybqjymy/p/16305408.html