C++ QWeb页面与多线程
我有以下代码:C++ QWeb页面与多线程,c++,multithreading,qt,qwebkit,qwebpage,C++,Multithreading,Qt,Qwebkit,Qwebpage,我有以下代码: class TestThread : public QThread { public: void run() { QFile file("test.html"); file.open(QIODevice::ReadOnly); QWebPage page; page.mainFrame()->setHtml(file.readAll()); qDebug() << p
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();
}
classtestthread:publicqthread
{
公众:
无效运行()
{
QFile文件(“test.html”);
open(QIODevice::ReadOnly);
QQ网页;
page.mainFrame()->setHtml(file.readAll());
qDebug()到html();
qDebug()我在Linux操作系统中遇到了这个问题。在Windows中,我收到了消息“必须在GUI线程中创建小部件”。但是QWebPage中的内容是正确的。因此,我不会将QWebPage用于我的任务。请同时发布test.html的内容。您实际需要的两个html之间有第三个html正在编写。我无法编辑我的帖子。我收到消息:“您的帖子没有太多的上下文来解释代码部分;请更清楚地解释您的场景。”:-(可能是文件没有关闭。只是胡乱猜测……不,文件没有扮演任何角色。问题在线程中!
"<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>"