#include#include #include int main() { QString filePath = "/home/user/Documents/myfile.txt"; QFileInfo fileInfo(filePath); QString fileName = fileInfo.fileName(); std::cout << "File name: " << fileName.toStdString() << std::endl; return 0; }
#includeThis code creates a `QDir` object for the `/usr/bin` directory, and then creates a `QFileInfo` object for the `ls` command in that directory. It then prints the file name to the console. Package/library: Qt#include int main() { QDir directory("/usr/bin"); QFileInfo fileInfo(directory.absoluteFilePath("ls")); QString fileName = fileInfo.fileName(); std::cout << "File name: " << fileName.toStdString() << std::endl; return 0; }