使用wxHtmlWindow在后台下载网页
我正在使用 wxWidgets 将网站的内容下载到 wxHtmlWindow 控件中。除了一件事之外,这工作完美无缺。下载数据时整个图形用户界面似乎冻结了,这对我的应用程序来说是一个很大的问题。在大多数其他 wxWidgets 类方法中,即使有问题的调用被认为是阻塞的,事件也会继续自动为您处理。这里的情况似乎并非如此,我想知道如何告诉 wxWidgets 在后台下载页面?我目前正在使用 LoadPage 方法。
我想我可以使用第二个线程,但是 wxWidgets 对通过主线程以外的任何线程更改任何窗口的状态施加的限制让我犹豫是否要深入研究这一点。有更好的办法吗?例如,原始http类在下载时不会阻塞窗口,所以我不明白为什么wxHtmlWindow(它肯定必须在内部使用原始http类)没有相同的行为。
I am using wxWidgets to download the contents of a website into a wxHtmlWindow control. This works flawlessly, except for one thing. The entire gui seems to freeze while the data is being downloaded, which is highly problematic for my application. In most other wxWidgets class methods, events continue to be processed automagicly for you even if the call in question is said to be blocking. This does not appear to be the case here, and I am wondering how I might tell wxWidgets to download the page in the background? I am currently using the LoadPage method.
I guess I could use a second thread, but with the restrictions that wxWidgets imposes on changing the state of any window through any thread other than the main one makes me hesitate to dive into this. Is there a better way? The raw http class, for instance, does not block the window while it's downloading so I don't understand why wxHtmlWindow, which surely must be using the raw http class internally, does not have the same behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是 wxHtmlWindow 使用同步套接字来获取 URL 的内容。调用层次结构如下:wxHtmlWindow -> wxHtmlParser -> wx文件系统-> wxURI-> wxHTTP-> wxHTTP::GetInputStream 。 GetInputStream 方法将使用以阻塞模式打开套接字。
您将需要使用单独的线程来获取网站的内容。
Unfortunately wxHtmlWindow uses synchronous sockets to fetch contents of a URL. Call hiearchy goes like this: wxHtmlWindow -> wxHtmlParser -> wxFileSystem -> wxURI -> wxHTTP -> wxHTTP::GetInputStream . The GetInputStream method will use the open a socket in blocking mode.
You will need to use a separate thread to fetch the contents of a website.