Results 1 to 2 of 2

Thread: QUrl::toLocalFile not working as exspected under Windows

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QUrl::toLocalFile not working as exspected under Windows

    Consider the following Code:

    Qt Code:
    1. QString path = "C:\\Development\\releases\\readme.txt";
    2.  
    3. qDebug() << "Original: " << path;
    4. qDebug() << "As URL: " << QUrl::fromLocalFile(path);
    5. qDebug() << "Result: " << QUrl::fromLocalFile(path).toLocalFile();
    To copy to clipboard, switch view to plain text mode 

    Real Output:
    Original: "C:\Development\releases\readme.txt"
    As URL: QUrl( "file:///C:/Development/releases/readme.txt" )
    Result: "C:/Development/releases/readme.txt"
    Exspected Output:
    Original: "C:\Development\releases\readme.txt"
    As URL: QUrl( "file:///C:/Development/releases/readme.txt" )
    Result: "C:\Development\releases\readme.txt"
    The path separator is not correct after the conversion. For Qt this is ok, because it can handle it, but if the path is used external this is a problem.

    Is there a way to get arround this (except for using everytime replace("/", "\\") if a url is converted to a file path)

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QUrl::toLocalFile not working as exspected under Windows

    take a look at QDir::toNativeSeparators.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    nightghost (6th August 2009)

Similar Threads

  1. I need example for Windows Mobile working program
    By Mr.QT in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2009, 09:19
  2. Qt4.5 windows TextFind tutorial not working
    By czlowiekcien in forum Newbie
    Replies: 10
    Last Post: 25th May 2009, 19:22
  3. Getting Phonon working on windows XP
    By keshava in forum Installation and Deployment
    Replies: 0
    Last Post: 12th May 2009, 16:37
  4. Windows fonts not working in QT?
    By frenetic in forum Installation and Deployment
    Replies: 2
    Last Post: 10th January 2009, 02:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.