A nice alternative to the accepted answer is to use
QUrl::fromUserInput
which is more flexible and covers also network paths.