QNetworkReply:在 QWebView 中禁用网络访问 [英] QNetworkReply: Network access is disabled in QWebView
问题描述
我无法将网站加载到我的 QWebView,QNetworkReply 返回错误:网络访问被禁用.从本地作品加载文件.
I cannot load website into my QWebView, QNetworkReply is returning me the error: Network Access is disabled. Loading files from local works.
我正在使用 Qt5.有谁知道为什么连接被禁用以及这条线如何影响这种情况:
I am using Qt5. Does anyone know why is connection disabled and how this line affects this situation:
QNetworkProxyFactory::setUseSystemConfiguration(false);
我的 eth0 连接工作正常,我可以 ping 任何网站.
My eth0 connection works properly, and I am able to ping any website.
推荐答案
来自 Qt 文档:调用 setUseSystemConfiguration() 会覆盖之前设置的任何应用程序代理或代理工厂.
所以要小心不要之前设置过任何其他代理.
From the Qt doc : calling setUseSystemConfiguration() overrides any application proxy or proxy factory that was previously set.
So be careful to not have set any other proxy before.
此外,如果您想检查网络访问,您可以这样做:
Moreover, if you want to check the Network access, you might do it that way :
QNetworkAccessManager m_pManager;
QNetworkConfigurationManager configManager;
m_pManager.setConfiguration(configManager.defaultConfiguration());
connect(&m_pManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(&m_pManager, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
并在您的插槽中:
if(accessible != QNetworkAccessManager::Accessible)
{
// case where the network is not available
}
对于回复,您可以在插槽 replyFinished()
中检查过程中是否出现错误.
And for the reply, you can check in the slot replyFinished()
if there was an error during the process.
这篇关于QNetworkReply:在 QWebView 中禁用网络访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!