KUrl url("file:///home/user/file.txt"); QString path = url.pathOrUrl(); // returns "/home/user/file.txt"
KUrl url("http://example.com"); QString path = url.pathOrUrl(); // returns "http://example.com"Here, we create a KUrl object representing a non-file URL, and call its pathOrUrl method to retrieve the original URL string. Both of these examples use the KUrl class from the KDE Frameworks library.