[Qt-interest] QFile SetFileName on windows 7

Gopalakrishna Bhat gopalakbhat at gmail.com
Mon Apr 4 18:51:17 CEST 2011


Hi All,

Thanks for the replies. It worked out for me.

With regards,
Gopalakrishna

On Mon, Apr 4, 2011 at 4:14 PM, Bo Thorsen <bo at fioniasoftware.dk> wrote:

> Hi,
>
> Den 04-04-2011 12:22, Gopalakrishna Bhat skrev:
>
>  I'm trying to open a file and read it in Windows 7. I get a weird
>> problem, whenever I set the filename the backslashes are converted into
>> forward slashes. What is the reason for this? Am I doing something wrong?
>>
>> The code snippet is below:
>>     QFile file;
>>     file.setFileName("C:\\development\\htmldict\\wb1913_.html");
>>     if(file.exists(file.fileName()))  {
>>         file.open(QIODevice::ReadOnly);
>>         qDebug()<<file.readAll();
>>     }
>>     else
>>         qDebug()<<"no  such  file"<<file.fileName();
>>
>> The output I get is
>>
>> no such file "C:/development/htmldict/wb1913_.html"
>>
>
> This is because Qt internally uses / as directory separator. You're not
> doing anything wrong.
>
> If you want to see your path as it really is, use
> QDir::toNativeSeparators().
>
> Bo Thorsen,
> Fionia Software.
>
> --
>
> Expert Qt and C++ developer for hire
> Contact me if you need expert Qt help
> http://www.fioniasoftware.dk
>



-- 
My blog http://gkbhat.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110404/d62fbe41/attachment.html 


More information about the Qt-interest-old mailing list