我正在尝试在超链接的单独窗口中打开文本文件。这就是我所拥有的:
#include "aboutdialog.h"
#include "ui_aboutdialog.h"
aboutdialog::aboutdialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::aboutdialog)
{
ui->setupUi(this);
this->setFixedSize(550,380);
}
aboutdialog::~aboutdialog()
{
delete ui;
}
void aboutdialog::on_pushButton_clicked()
{
close();
}
// Open Qt Libraries Terms and Conditions
void aboutdialog::on_label_6_linkActivated(const QString &link)
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Qt libraries Terms and Conditions"),
"",
tr("Text Files (/LICENSE.LGPL)"));
if(!fileName.isEmpty())
{
QFile file(fileName);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
file.readAll();
}
}
}
它告诉我:
ShellExecute 'LICENSE.LGPL' failed (error 2)
有人可以指出问题吗?
答案 0 :(得分:0)
您的UI文件很可能包含带有链接的QLabel,并且此QLabel将openExternalLinks
属性设置为true。
答案 1 :(得分:0)
也许
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Qt libraries Terms and Conditions"),
"/LICENSE.lgpl",
tr("LICENSE (*.lgpl);;All Files (*)")
);