Qt 从菜单栏打开文件


Qt从菜单栏的下拉菜单选择文件

构造函数中设置打开动作信息

	//打开文件
	m_menu = ui.menu;
//	m_menu->menuAction = new QAction(QIcon(tr("images/open.ico")), tr("打开文件"), this);
	QAction *Action = new QAction(tr("打开文件"), this);
	//设置打开文件按钮的快捷方式
	Action->setShortcut(tr("Ctrl+o"));
	m_menu->addAction(Action);
	
	//关联信号和槽
	QObject::connect(Action, SIGNAL(triggered()), this, SLOT(OpenFile()));

打开文件的实现函数

void player_qt::OpenFile(){
    //同时打开多个文件
	QStringList str_path_list = QFileDialog::getOpenFileNames(this, tr("选择视频文件"), tr("/home"), tr("视频文件(*.mp4 *.m3u8 *.flv);;"));
	QString str_path = "";
	for (int i = 0; i < str_path_list.size(); i++){
		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 += "\n";*/
	}
	//Qstring转string
	std::string StrPath = str_path.toStdString();
	
}

更多参考


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM