1
我有这样的代码:QWebPage和多线程
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>"
在第二遍,有太多的标签。什么是解决方法?或者我的错误在哪里?
请发布test.html的内容。 – Troubadour 2012-07-21 20:08:51
还有第三个html被写在你实际需要的两个之间的某处。 – 2012-07-21 20:15:01
我无法编辑我的帖子。我收到消息:“您的帖子没有太多的上下文来解释代码段,请更清楚地解释您的情况。” :-( – brainstream 2012-07-21 20:17:04