Reputation: 3843
Everything I read indicates that QDesktopServices::openUrl
is the platform-agnostic way to open a document using the default program, and it works great, almost all of the time.
I say almost, because it always seems to fail if I pass it a network path. Combing through the source I see that ShellExecute returns error code 2.
Example:
QUrl localpath = QUrl::fromLocalFile("C:/temp/myfile.txt");
QUrl networkpath = QUrl::fromLocalFile("//192.168.0.5/my folder/myfile.txt");
QDesktopServices::openUrl(localpath); //works fine
QDesktopServices::openUrl(networkpath); //always fails
Is there a way I can clean up a network path to open correctly? I'm running Qt 4.8 on Windows. Switching the forward slashes to backslashes doesn't help.
Upvotes: 1
Views: 1105
Reputation: 11
You should use QUrl::TolerantMode if you have spaces in your path. try this:
QDesktopServices::openUrl(QUrl("file:////192.168.0.5/my folder/myfile.txt", QUrl::TolerantMode));
Upvotes: 1