【问题标题】:QWebPage and multithreadingQWebPage 和多线程
【发布时间】:2012-07-20 16:16:24
【问题描述】:

我有这个代码:

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的内容也贴出来。
  • 在你真正想要的两者之间的某个地方写了第三个 html。
  • 我无法编辑我的帖子。我收到消息:“您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的场景。” :-(
  • 可能是文件没有关闭。只是一个疯狂的猜测......
  • 不,文件没有任何作用。线程中的问题!

标签: c++ multithreading qt qwebkit qwebpage


【解决方案1】:

我在 Linux 操作系统中遇到了问题。在 Windows 中,我收到消息“必须在 GUI 线程中创建小部件”。但是 QWebPage 中的内容是正确的。所以,我不会使用 QWebPage 来完成我的任务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    相关资源
    最近更新 更多