Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Qt中的Sphinx积分_Html_C++_Qt_Python Sphinx_Qtextbrowser - Fatal编程技术网

Html Qt中的Sphinx积分

Html Qt中的Sphinx积分,html,c++,qt,python-sphinx,qtextbrowser,Html,C++,Qt,Python Sphinx,Qtextbrowser,我想集成Sphinx文档功能来帮助我的Qt项目。但是,当包含Sphinx的HTML文件时,格式会有所不同,并且没有文件链接。例如: QFile file("/home/user1/project/Sphinx/build/html/intro.html"); if (!file.open(QIODevice::Readonly)) qDebug() << "Didn't open file"; QTextStream in(&file); ui->textBro

我想集成Sphinx文档功能来帮助我的Qt项目。但是,当包含Sphinx的HTML文件时,格式会有所不同,并且没有文件链接。例如:

QFile file("/home/user1/project/Sphinx/build/html/intro.html");
if (!file.open(QIODevice::Readonly))
    qDebug() << "Didn't open file";
QTextStream in(&file);
ui->textBrowser->setText(in.readAll());
QFile文件(“/home/user1/project/Sphinx/build/html/intro.html”);
如果(!file.open(QIODevice::Readonly))
qDebug()文本浏览器->设置文本(在.readAll()中);
错误:QTextBrowser:没有用于_sources/intro.txt的文档

这将导致textBrowser打开正确的文件,但不会以正确的HTML编码显示页面,也不会跟随链接,即使这些HTML文件包含在相同的路径中(因为我已将整个Sphinx项目复制到Qt项目中)


是否有一些方法可以打包整个Sphinx项目,这样就不需要包含多个文件,或者多个文件的包含是一种方法,而我只是处理得不正确?

而不是读取所有文本并使用
setText()
进行设置,您必须使用
setSource()
方法,并使用
QUr::fromLocalFile()
方法将其传递给
QUrl

main.cpp

#include <QtWidgets>

class Widget: public QWidget
{
    Q_OBJECT
public:
    Widget(QWidget *parent=nullptr):
        QWidget(parent),
        m_text_browser(new QTextBrowser)
    {
        m_lineedit = new QLineEdit;
        auto button = new QPushButton("Load");

        auto lay = new QVBoxLayout{this};
        auto hlay = new QHBoxLayout;
        lay->addLayout(hlay);
        hlay->addWidget(m_lineedit);
        hlay->addWidget(button);
        lay->addWidget(m_text_browser);

        connect(button, &QPushButton::clicked, this, &Widget::on_clicked);
    }
private slots:
    void on_clicked(){
        QString fileName = QFileDialog::getOpenFileName(this,
                                                        tr("Open Image"),
                                                        QDir::homePath(),
                                                        tr("HTML Files (*.html)"));
        m_lineedit->setText(fileName);
        m_text_browser->setSource(QUrl::fromLocalFile(fileName));
    }
private:
    QTextBrowser *m_text_browser;
    QLineEdit *m_lineedit;
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.showMaximized();
    return a.exec();
}

#include "main.moc"
#包括
类Widget:publicqwidget
{
Q_对象
公众:
小部件(QWidget*parent=nullptr):
QWidget(母公司),
m_文本浏览器(新的QTextBrowser)
{
m_lineedit=新的QLineEdit;
自动按钮=新按钮(“加载”);
自动布局=新的QVBoxLayout{this};
auto hlay=新的QHBoxLayout;
布局->添加布局(hlay);
hlay->addWidget(m_lineedit);
hlay->addWidget(按钮);
lay->addWidget(m_text_浏览器);
连接(按钮,&QPushButton::单击,此,&Widget::on_单击);
}
专用插槽:
单击时无效(){
QString fileName=QFileDialog::getOpenFileName(此,
tr(“开放图像”),
QDir::homePath(),
tr(“HTML文件(*.HTML)”);
m_lineedit->setText(文件名);
m_text_browser->setSource(QUrl::fromLocalFile(fileName));
}
私人:
QTextBrowser*m_text_浏览器;
QLineEdit*m_lineedit;
};
int main(int argc,char*argv[])
{
质量保证申请a(argc、argv);
小部件w;
w、 showMaximized();
返回a.exec();
}
#包括“main.moc”

您能通过github共享您的Sphinx项目吗?目前,Sphinx提供了基本的快速入门教程,添加了一个页面(“简介”)来测试链接功能。如果您提供一个示例,将为我们节省大量时间。:-)这是有效的:)代码的完整副本已添加在:精彩!多谢了,真的帮了大忙