【发布时间】:2016-06-17 16:06:00
【问题描述】:
我是 Qt 的新手,我正在开发一个搜索应用程序,它可以搜索并列出文件夹中的所有视频。我想生成可点击的文件路径,可以在 cilcked 时运行视频文件。这是我想要做的代码:
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
}
谢谢!
【问题讨论】:
-
你到底在问什么?如何使“搜索结果”中的行在 UI 中可点击或如何在点击一行时启动播放器?要启动播放器,您可以使用 QDesktopServices::openUrl(QUrl(QString("file:///" + filePath))); .使每一行都可点击。看起来您将 QTextEdit 用于“搜索结果”。将其 'acceptRichText' 属性设置为 true 并对其进行格式化,以便线条代表可点击的链接
-
我的问题实际上是如何做到这两点。我希望打印出来的路径是可点击的,当用户点击它时,它会运行路径指向的视频。感谢您的建议,如果我能解决,我会尝试。
-
实际上,打开视频文件很容易,因为我可以使用 system() 函数来运行。但是我就是不知道怎么让每一行都变成一个按钮来执行功能。
-
您想要按钮或“可点击文本”之类的页面中的链接(恕我直言,这种控制更好,但这是您的选择)?顺便说一句,您将 Qt 与特定于操作系统的调用混合使用。一旦使用 Qt,您就可以使您的程序完全可移植,但这又是您的选择...
-
可点击的文字会更好。但我接受任何东西,只要它运行。我正在考虑使用html作为文本,但似乎html无法运行onclick功能(或者只是我不知道)
标签: c++ qt user-interface