QUrl url("file:///home/user/documents/report.txt"); if (url.isLocalFile()) { // Do something with the local file }
QString filePath = "/home/user/documents/report.txt"; QUrl url = QUrl::fromLocalFile(filePath);In both examples, we use the isLocalFile() method to check if the given URL refers to a local file. In the first example, we perform some action if the URL is a local file. In the second example, we convert a local file path to a URL using the fromLocalFile() method. Package Library: Qt Core Library