QNetworkReply: Network access is disabled in QWebV

2019-07-12 04:23发布

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条回答
爷的心禁止访问
2楼-- · 2019-07-12 05:09

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.

查看更多
登录 后发表回答