0

Is there a way to dump content of QTextBrowser object to a file?

demonplus
  • 5,613
  • 12
  • 49
  • 68
Nimesh
  • 1
  • 2

1 Answers1

1

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"
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • I figured out right after submitting this question and turns out I did exactly as your code. Thank you, Piotr - it works great! – Nimesh Jan 04 '11 at 22:32