QT:暂停功能流程,直到 QWebView SIGNAL 完成

发布于 2024-09-28 07:20:08 字数 609 浏览 1 评论 0原文

我主要是一名网络开发人员,所以我的问题可能是某种初学者。

我正在编写一个与 QWebView 内容一起使用的函数,这是一种在加载的网页上执行操作的宏脚本。

代码是这样的:

somefunction() {

QWebView *webView;
webView->load(QUrl("http://www.google.com"));
<...> here I want to pause the code until the page is loaded <...>
here goes the code of html manipulation, click on another link
<...> here I want to pause the code until the page is loaded <...>

}

好的,所以在我写“<...>”的地方我想暂停代码,直到页面加载<...>”我不知道如何暂停该功能并使其等待页面完成加载。我了解信号和槽。但是如果我在这里使用槽,我将不得不在另一个函数中继续 - 在 SLOT 函数中,但我想将所有代码和逻辑留在 somefunction() 中。怎么做呢?

I'm a mostly webdeveloper, so my question can be somekind of a beginners.

I'm writing a function which works with QWebView content, some kind of a macro script which makes action on loaded web page.

code is something like that:

somefunction() {

QWebView *webView;
webView->load(QUrl("http://www.google.com"));
<...> here I want to pause the code until the page is loaded <...>
here goes the code of html manipulation, click on another link
<...> here I want to pause the code until the page is loaded <...>

}

Ok, so in places where I wrote "<...> here I want to pause the code until the page is loaded <...>" I dunno what to do to pause the function and make it wait for page to finish loading. I know about signals and slots. But if I use slot here, I will have to continue in another function - in SLOT function, but I want to leave all the code and logic in somefunction(). How to do that?

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

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

发布评论

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

评论(1

一城柳絮吹成雪 2024-10-05 07:20:08

您可以使用嵌套的 QEventLoop 来同步异步处理,例如页面加载。当发出 loadFinished 时,只需 exit() 循环即可从进入循环的位置恢复执行。

另一方面,将处理拆分为多个函数(槽)也不是那么糟糕。代码和逻辑仍然位于同一个类中的同一位置。

You can use a nested QEventLoop to synchronize asynchronous processing like page loading. When loadFinished is emitted, just exit() the loop to resume execution from where you entered the loop.

On the other hand, splitting processing to multiple functions (slots) isn't that bad either. The code and logic is still in the same place in the same class.

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