我有这个代码:
class TestThread : public QThread
{
public:
void run()
{
QFile file("test.html");
file.open(QIODevice::ReadOnly);
QWebPage page;
page.mainFrame()->setHtml(file.readAll());
qDebug() << page.mainFrame()->toHtml();
qDebug() << "\n\n\n\n";
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
for(int i = 0; i < 2; ++i)
{
TestThread thread;
thread.start();
thread.wait();
}
return a.exec();
}
并输出:
"<html><head>
<title>My page</title>
</head>
<body>
My content
</body></html>"
"<html><head></head><body><html>
<head>
<title>My page</title>
</head>
<body>
My content
</body>
</html></body></html>"
在第二遍中,标签过多。什么是解决方法?或者我的错误在哪里?