本文整理汇总了C++中QNetworkProxy::setCapabilities方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkProxy::setCapabilities方法的具体用法?C++ QNetworkProxy::setCapabilities怎么用?C++ QNetworkProxy::setCapabilities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkProxy
的用法示例。
在下文中一共展示了QNetworkProxy::setCapabilities方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadSettings
void NetworkAccessManager::loadSettings()
{
QSettings settings;
settings.beginGroup(QLatin1String("proxy"));
QNetworkProxy proxy;
if (settings.value(QLatin1String("enabled"), false).toBool()) {
int proxyType = settings.value(QLatin1String("type"), 0).toInt();
if (proxyType == 0)
proxy = QNetworkProxy::Socks5Proxy;
else if (proxyType == 1)
proxy = QNetworkProxy::HttpProxy;
else { // 2
proxy.setType(QNetworkProxy::HttpCachingProxy);
#if QT_VERSION >= 0x040500
proxy.setCapabilities(QNetworkProxy::CachingCapability | QNetworkProxy::HostNameLookupCapability);
#endif
}
proxy.setHostName(settings.value(QLatin1String("hostName")).toString());
proxy.setPort(settings.value(QLatin1String("port"), 1080).toInt());
proxy.setUser(settings.value(QLatin1String("userName")).toString());
proxy.setPassword(settings.value(QLatin1String("password")).toString());
}
#if QT_VERSION >= 0x040500
NetworkProxyFactory *proxyFactory = new NetworkProxyFactory;
if (proxy.type() == QNetworkProxy::HttpCachingProxy) {
proxyFactory->setHttpProxy(proxy);
proxyFactory->setGlobalProxy(QNetworkProxy::DefaultProxy);
} else {
proxyFactory->setHttpProxy(QNetworkProxy::DefaultProxy);
proxyFactory->setGlobalProxy(proxy);
}
setProxyFactory(proxyFactory);
#else
setProxy(proxy);
#endif
settings.endGroup();
#ifndef QT_NO_OPENSSL
QSslConfiguration sslCfg = QSslConfiguration::defaultConfiguration();
QList<QSslCertificate> ca_list = sslCfg.caCertificates();
QList<QSslCertificate> ca_new = QSslCertificate::fromData(settings.value(QLatin1String("CaCertificates")).toByteArray());
ca_list += ca_new;
sslCfg.setCaCertificates(ca_list);
QSslConfiguration::setDefaultConfiguration(sslCfg);
#endif
settings.beginGroup(QLatin1String("network"));
QStringList acceptList = settings.value(QLatin1String("acceptLanguages"),
AcceptLanguageDialog::defaultAcceptList()).toStringList();
acceptLanguage = AcceptLanguageDialog::httpString(acceptList);
settings.endGroup();
}
示例2: main
int main(int argc, char** argv) {
// Parse options
// TODO: http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKCmdLineArgs.html
{
QStringList arguments = getCliArguments(argc, argv);
if ((arguments.indexOf("-h") != -1) || (arguments.indexOf("--help") != -1)) {
qDebug() << "QtWeb options:";
qDebug() << "";
qDebug() << "--maximize";
qDebug() << "";
qDebug() << "--url";
qDebug() << "--user-agent";
qDebug() << "--socks host:port";
qDebug() << "--socks-resolver";
qDebug() << "--extra-enabled";
return EXIT_SUCCESS;
}
int optionIndex = 0;
// maximize
if ((optionIndex = arguments.indexOf("--maximize")) != -1) {
options.maximize = true;
}
// url
if ((optionIndex = arguments.indexOf("--url")) != -1) {
options.url = arguments.at(optionIndex + 1);
}
// user agent
if ((optionIndex = arguments.indexOf("--user-agent")) != -1) {
options.userAgent = arguments.at(optionIndex + 1);
Wrapper::QWebPage::userAgent = options.userAgent;
}
// socks
if ((optionIndex = arguments.indexOf("--socks")) != -1) {
options.socks = arguments.at(optionIndex + 1);
}
// socks resolver
if ((optionIndex = arguments.indexOf("--socks-resolver")) != -1) {
options.socksResolver = true;
}
// enable extra
if ((optionIndex = arguments.indexOf("--extra-enabled")) != -1) {
options.extraEnabled = true;
}
qDebug() << "Maximize" << options.maximize;
qDebug() << "Load" << options.url;
qDebug() << "User-agent" << options.userAgent;
qDebug() << "Socks" << options.socks;
qDebug() << "Socks resolver" << options.socksResolver;
qDebug() << "Extra enabled" << options.extraEnabled;
}
QApplication a(argc, argv);
// release view
Lambda qHandler([&]() {
view.reset();
});
QObject::connect(&a, SIGNAL(aboutToQuit()), &qHandler, SLOT(call()));
view.reset(new QWebView);
view->setPage(new Wrapper::QWebPage);
// add "http://"
if (options.url.indexOf("://") == -1) {
options.url = QLatin1String("http://") + options.url;
}
// socks
if (options.socks.length()) {
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::Socks5Proxy);
int colonPosition = options.socks.lastIndexOf(":");
if (colonPosition == -1) {
qDebug() << "Malformed proxy (HOST:PORT is needed)";
return EXIT_FAILURE;
}
proxy.setHostName(options.socks.left(colonPosition));
proxy.setPort(options.socks.right(options.socks.length() - 1 - colonPosition).toInt());
if (options.socksResolver) {
proxy.setCapabilities(proxy.capabilities() | QNetworkProxy::HostNameLookupCapability);
} else {
proxy.setCapabilities(proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability);
}
view->page()->networkAccessManager()->setProxy(proxy);
qDebug() << "Proxy installed";
}
// Add inspector.
view->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
if (options.extraEnabled) {
view->page()->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
//.........这里部分代码省略.........