#include#include int main() { QFileInfo fileInfo("/path/to/file.txt"); QString absolutePath = fileInfo.absolutePath(); qDebug() << "Absolute path:" << absolutePath; return 0; }
#includeThis example uses QFileDialog to show a file dialog and get the path of a selected file. The path is then passed to a QFileInfo object, and the absolutePath function is called to get the absolute path of the file. The absolutePath is then used to do something with the file. Package Library: Qtint main() { QString filePath = QFileDialog::getOpenFileName(); QFileInfo fileInfo(filePath); QString absolutePath = fileInfo.absolutePath(); // Use absolutePath to do something with the file... return 0; }