Qt打开文件对话框同时选中多个文件或单个文件

Qt中打开单个文件
//str_path为文件路径
QString str_path = QFileDialog::getOpenFileName(this, tr("选择转码文件"), tr("/home"), tr("视频文件(*.mp4 *.m3u8);;所有文件(*.*);;"));
打开多个文件
QString strs;
QStringList file_list, output_name;
QStringList str_path_list = QFileDialog::getOpenFileNames(this, tr("选择转码文件"), tr("/home"), tr("视频文件(*.mp4 *.m3u8);;所有文件(*.*);;"));
	for (int i = 0; i < str_path_list.size(); i++){
		QString str_path = str_path_list[i];
		//单个文件路径
		qDebug() << "path=" << str_path;
		QFileInfo file = QFileInfo(str_path);
		//获得文件名
		QString file_name = file.fileName();
		file_list.append(str_path);
		output_name.append(file_name);
		strs.append(file_name);
		strs += "
";
	}

更多参考

原文地址:https://www.cnblogs.com/ZY-Dream/p/10571490.html