QNetworkReply: Network access is disabled in QWebView

喜夏-厌秋 提交于 2020-01-04 07:11:22

问题


I cannot load website into my QWebView, QNetworkReply is returning me the error: Network Access is disabled. Loading files from local works.

I am using Qt5. Does anyone know why is connection disabled and how this line affects this situation:

QNetworkProxyFactory::setUseSystemConfiguration(false);

My eth0 connection works properly, and I am able to ping any website.


回答1:


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)));

and in your slot :

if(accessible != QNetworkAccessManager::Accessible)
    {
        // case where the network is not available
    }

And for the reply, you can check in the slot replyFinished() if there was an error during the process.



来源:https://stackoverflow.com/questions/35337304/qnetworkreply-network-access-is-disabled-in-qwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!