qt中文件路径的编码

Encoding of filepath in qt

本文关键字:编码 路径 文件 中文 qt      更新时间:2023-10-16

我正在编写读取WAV文件的方法。当我像"E:\waffile.wav"一样将它与文件路径一起使用时,它工作得很好。但是路径可以包含带有俄语符号(cp1251)的:
"E:/谷歌驱动器/谷歌Диск/РАБОТА/IP-PHONE/vaneev/guncans.wav"

void WAV::open(QString path)
{
    qDebug() << path; // in console displayed valid path
    FILE *pFile = fopen(path.toStdString().c_str(),"rb"); // but there is an error 

路径如下所示:
E:/GoogleDrive/GoogleР"РСРДР"/РРАР'РУРўР/IP-PHONE/vaneev/guncans.wav

我该怎么解决这个问题?(我使用QT)

听起来像是在从PercentEncoding或toEncoded 中寻找

void WAV::open(QString path)
{     
     FILE *pFile = fopen(path.toLocal8Bit(),"rb");

我刚刚使用了方法toLocal8Bit()。它起作用了!