QFile :: open失败与unicode文件名 [英] QFile::open fails with unicode filename

查看:1741
本文介绍了QFile :: open失败与unicode文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用QFile :: Open打开一个文件,其中我的文件名是unicode:

I want to open a file with QFile::Open where my file name is unicode:

           QString fname(QFile::decodeName("D:/أحدالأنشطة.txt"));
           QFile qFile(fname);

           bool b=qFile.open(QIODevice::ReadOnly);
           if(b)
           {
               FILE* filedesc = fdopen(qFile.handle(), "rb");
               if(filedesc!=NULL)
               {
                   char* nb=(char*)malloc(2*sizeof(char));
                   qDebug()<<"opened ";
                   size_t size=fread(nb,sizeof(char),2,filedesc);
                   fclose(filedesc);
                   qDebug()<<"filedesc closed size "<<size<<"nb "<<QString::fromAscii(nb,2);
                   nb=NULL;
                   free(nb);

               }else qDebug()<<"filedesc failed   error"<<strerror(errno);


            }else
                qDebug()<<"qFile failed   error"<<strerror(errno);

它失败了,我得到:

qFile failed   error No error 

任何帮助将不胜感激。 / p>

any help will be appreciated.

推荐答案

如果数据在 WCHAR 数组中, $ c> QString filename((QChar *)yourWcharData);

If the data is in WCHAR array than just use QString filename((QChar*) yourWcharData);

这篇关于QFile :: open失败与unicode文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆