Note that there are some explanatory texts on larger screens.

plurals
  1. POQFile Unicode path - file does not exist
    primarykey
    data
    text
    <p>I write a <a href="https://addons.mozilla.org/en-US/firefox/addon/youtube-mp3-podcaster/" rel="nofollow">Firefox plugin</a> that calls out to external programs to get work done :). The trouble is Firefox can't handle Unicode when you're passing arguments, so I'm having to jump through some hoops when I call my exes.</p> <p>What I've been doing is using URI encoded strings instead, and I'm using the QT library to do the hard stuff of handling Unicode Strings. But I can't get QT's QFile to find anything on a Unicode path.</p> <p>I start with a string like this:</p> <p>C:\temp\私\Power Up!.mp3</p> <p>I encode it into this:</p> <p>C%3A%5Ctemp%5C%E7%A7%81%5CPower%20Up!.mp3</p> <p>Then I pass it as a command line argument. Right now I'm passing it in the Visual C++ 2010 Express Edition compiler's Debugging Command Line Arguments.</p> <p>Finally I try to do this:</p> <pre><code>std::string fileName( "c:\\temp\\debug " ); std::string extension (".txt"); ofstream a_file ( fileName + extension ); QString filepath ( argv[argc - 1] ); QString url = QUrl::fromPercentEncoding( filepath.toUtf8() ).replace("\\","/"); a_file &lt;&lt; "Param: " &lt;&lt; url.replace("\\","/").toStdString() &lt;&lt; "\n\n"; QFile myQfile ( url.replace("\\","/") ); // Replacing every backslash with a forward slash // QT doesn't allow backslashes in paths. if( !myQfile.exists() ){ a_file &lt;&lt; "The param \"" &lt;&lt; myQfile.fileName().toStdString() &lt;&lt; "\" is not a file."; a_file.close(); exit(1); }//END IF </code></pre> <p>If I don't have a path with a '私' character it works fine, but otherwise the call to exists() returns false and I end up exiting out. I know the file is there though, and when I check my debug file in notepad++ it has the right characters. </p> <p>Can anyone see what I'm doing wrong? </p> <p>Edit: </p> <p>I think I may have got it.</p> <p>First I switched to a wmain like so:</p> <pre><code>int wmain(int argc, wchar_t *argv[]) </code></pre> <p>Then I set up my QStrings like so:</p> <pre><code>QString filepath = QString::fromWCharArray ( argv[argc - 1] ); QString url = QUrl::fromPercentEncoding( filepath.toLocal8Bit() ); TagLib::FileRef f( url.toStdWString().c_str() ); </code></pre> <p>This works so far. I need to do some more testing :), and I'm 90% sure this won't compile in Linux/OSX (I need to build QT in Linux to find out, and look into the wchar_t macro).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload