QString path = "mydir/myfile.txt"; QFileInfo fileInfo(path); QString absPath = fileInfo.absFilePath(); qDebug() << "Absolute path to" << path << "is" << absPath;
QDir dir("/home/user/Documents"); QFileInfoList files = dir.entryInfoList(); foreach (const QFileInfo& fileInfo, files) { QString absPath = fileInfo.absFilePath(); qDebug() << "Absolute path to" << fileInfo.fileName() << "is" << absPath; }In this example, we create a QDir object for a directory "/home/user/Documents". We then generate a list of QFileInfo objects using entryInfoList(), which returns information about all the files and directories in that directory. We loop over each file in the list and call absFilePath() to get the absolute path to each file. We print out the file name and its absolute path using qDebug(). The output might be something like "Absolute path to myfile.txt is /home/user/Documents/myfile.txt". In both examples, we are using the Qt library, specifically the QtCore package, which includes QFileInfo and other essential classes for building Qt applications.