How to get the file name from a path in Qt?

You can use the QFileInfo class to retrieve the file name from a path. Here is an example code using Qt:

QString filePath = "/path/to/file.txt";
QFileInfo fileInfo(filePath);
QString fileName = fileInfo.fileName();

// 输出文件名
qDebug() << "File name: " << fileName;

Output result:

File name: "file.txt"

In the example above, we first create a QFileInfo object and pass the file path as a parameter to it. Then, we use the fileName() function to retrieve the file name. Finally, we use the qDebug() function to output the file name.

I hope this is helpful to you!

bannerAds