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();
}