QWebElement 在单独的线程中操作 QWebPage

发布于 2024-08-21 09:32:48 字数 511 浏览 2 评论 0原文

我在主线程中创建了一个 QWebPage (您无法在其他地方创建它)。我想使用 Qt 4.6 中引入的 QWebElement API 来操作此页面,但在单独的线程中。这样该线程将获取对页面的引用并执行我需要的必要的树遍历和属性更改。

正如 Threads and QObjects 文档页面所解释的那样,操作是不安全的不拥有它们的线程中的 QObject除非开发人员可以确保相关 QObject 在进行此操作时不会处理事件。

现在,这个 QWebPage 也显示在 QWebView 中,但是主线程将在等待工作线程完成时被阻塞(实际上有很多工作线程,在许多不同的页面上工作)。因此,当操作正在进行时,主事件循环将不会运行。

因此,我相信手术是安全的。 我错了吗?我错过了什么吗?我基本上是在请求保证这不会在我脸上爆炸......

I have a QWebPage created in the main thread (you can't create it anywhere else). I would like to manipulate this page using the QWebElement API introduced in Qt 4.6, but in a separate thread. So that thread would acquire a reference to the page and perform the necessary tree walking and attribute changes I need.

As the Threads and QObjects doc page explains, it is unsafe to manipulate QObjects in threads that don't own them unless the developer can ensure that the QObject in question will not be processing events while this manipulation is going on.

Now, this QWebPage is also being displayed in a QWebView, but the main thread will be blocked while waiting for the worker thread to finish (actually many of them, working on many different pages). Hence, the main event loop will not be running while the operation is in progress.

Thus, I believe the operation to be safe. Am I mistaken? Have I missed something? I'm basically asking for reassurance that this will not blow up in my face...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎的声音 2024-08-28 09:32:48

我确实认为你是对的,而且它是安全的。至少,你让我确信了:)

I do think you're right, and it is safe. At least, you have me convinced :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文