以下内容是摘抄大神博客:
https://blog.csdn.net/w_yqrx123/article/details/82754232
/去掉路径中的最后一个
void Widget::on_pushButton_4_clicked()
{
QString path = "E:/hello/123/234.txt";
int index = path.lastIndexOf("/");
path = path.left(index);
qDebug()<<"path=="<<path;//"E:/hello/123"
//或者是:
QString path = "E:\\hello\\123\\234.txt";
int index = path.lastIndexOf("\\");
path = path.left(index);
qDebug()<<"path=="<<path;//"E:\\hello\\123"
}