#include#include int main() { QFileInfo fileInfo("example/file.txt"); qDebug() << fileInfo.absoluteDir().absolutePath(); // prints "/home/user/example" return 0; }
#includeThis example creates a QFileInfo object for a directory located at an absolute path "/home/user/example". The absoluteDir() function returns the absolute path of the directory that the directory resides in, which is also "/home/user/example" in this case. Package library: Qt Core#include int main() { QFileInfo dirInfo("/home/user/example"); qDebug() << dirInfo.absoluteDir().absolutePath(); // prints "/home/user/example" return 0; }