c++ - Qt:如何制作可点击路径以在点击时运行视频文件

标签 c++ qt user-interface

我是 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

}

以下是用户界面的截图,以防万一: enter image description here

谢谢!

最佳答案

构建 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/

相关文章:

c# - 我们可以使用 QT 和 C# 来创建 GUI 吗?

java - 单元格渲染器 Java Swing 的单元格的圆角边缘

user-interface - 如何在没有GUI的情况下运行MATLAB并获得图形结果?

C++ 类构造函数/析构函数

switch 语句中的 C++ 函数未执行

c++ - C++ 中的 cin 试图将字符串值分配给 int 变量?

c++ - 链接器错误 : cannot link to '&.obj'

C++ sdl : can i have an sdl-opengl window inside a menu and buttons i created with glade?

c++ - 如何从打开的窗口列表中检索 QWidget

qt - 为什么我没有 Qt Gui Application 选项?