#include#include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QDir dir; QString path = dir.currentPath(); // Get the current working directory QString canonicalPath = dir.canonicalPath(); // Get the canonical path of the current working directory qDebug() << "Path:" << path; // Output: "Path: /path/to/current/directory" qDebug() << "Canonical path:" << canonicalPath; // Output: "Canonical path: /path/to/current/directory" return app.exec(); }
#includePackage library: Qt.#include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QDir dir; QString filePath = "file.txt"; // The file is assumed to be in the current working directory QString canonicalFilePath = dir.canonicalFilePath(filePath); // Get the canonical path of the file qDebug() << "File path:" << filePath; // Output: "File path: file.txt" qDebug() << "Canonical file path:" << canonicalFilePath; // Output: "Canonical file path: /path/to/current/directory/file.txt" return app.exec(); }