开发者

QT: Pause function flow till QWebView SIGNAL is completed

开发者 https://www.devze.com 2023-01-20 23:12 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号