[Qt-interest] QFile SetFileName on windows 7

Bo Thorsen bo at fioniasoftware.dk
Mon Apr 4 12:44:29 CEST 2011


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



More information about the Qt-interest-old mailing list