我是 Qt 的新手,我正在开发一个搜索应用程序,它可以搜索并列出文件夹中的所有视频。我想生成可点击的文件路径,在点击时可以运行视频文件。这是我正在尝试执行的代码:
void MainWindow::on_pushButton_7_clicked()
{
QString key = ui->key->toPlainText(); //get the search keyword
QString text = ui->DIR->toPlainText(); //get the directory
string cmd = "./search_by_keyword.sh "+text.toStdString()+" "+key.toStdString();
//command to run a shell script with 2 arguments
system("chmod +x search_by_keyword.sh");
system(cmd.c_str()); //run the script which produce a txt file containing the search results
ifstream fin { "search_result.txt" }; //read result and print out
string s;
QStringList all;
while(!fin.eof()){
getline(fin,s);
string convert = s; //I want each "s" produced to be clickable, and it run the video in the path when clicked
QString str = convert.c_str();
all << str;
}
fin.close();
ui->searchResult->setText(all.join("\n")); //searchResult is currently a textBrowser
}
谢谢!
最佳答案
构建 QUrl 并将其添加到您的到达文本中。在这里阅读更多 - doc.qt.io/qt-5/qurl.html这里 - doc.qt.io/qt-5/qtwidgets-draganddrop-dropsite-example.html .另请阅读此 SO 问答 - stackoverflow.com/questions/16581425/…
关于c++ - Qt:如何制作可点击路径以在点击时运行视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37885936/