开发者

QTextBrowser content to File

开发者 https://www.devze.com 2023-02-03 00:44 出处:网络
Is the开发者_StackOverflow社区re a way to dump content of QTextBrowser object to a file?Below is a short, working example of how to do it.

Is the开发者_StackOverflow社区re a way to dump content of QTextBrowser object to a file?


Below is a short, working example of how to do it.

#include <QApplication>
#include <QFile>
#include <QTextBrowser>
#include <QTextStream>   


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QTextBrowser browser;
    browser.setHtml("<html><body>Some text...</body></html>");

    QFile file("out.txt");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return -1;

    QTextStream out(&file);
    out << browser.document()->toHtml();
    file.close();
    app.exec();
}

#include "main.moc"
0

精彩评论

暂无评论...
验证码 换一张
取 消