如何在 Qt 中设置应用程序范围的代理设置? [英] How can I set application wide proxy settings in Qt?

查看:98
本文介绍了如何在 Qt 中设置应用程序范围的代理设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前曾发布过关于我为让 Google 地图在 WebView 中显示所做的努力.我发现我需要安装 OpenSSL,以便 HTTPS 可用于某些 Google API.

I have posted previously about my efforts to get Google Maps to display in WebView. I discovered that I needed to install OpenSSL so that HTTPS could be used for some of the Google APIs.

这一切都很好,但现在在另一台机器上,我在配置 Qt 以使用系统代理时遇到了麻烦.对于这个,我们有一个不需要身份验证的系统代理,另一个需要.默认代理是需要身份验证的代理.

That's all well and good but now on a different machine I am having touble configuring Qt to use the system proxy. For this one we have one system proxy that does not require authentication and one that does. The default proxy is the one that does require authentication.

我有以下代码来指定代理:

I have the following code to specify the proxy:

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QNetworkProxy>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QNetworkProxy proxy;
     proxy.setType(QNetworkProxy::HttpProxy);
     proxy.setHostName("url.of.proxy.not.requiring.authentication");
     proxy.setPort(8080);
     QNetworkProxy::setApplicationProxy(proxy);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/Maps/main.qml"));
    viewer.showExpanded();

    return app.exec();
}

当我运行这个应用程序时,我在 WebView 中看到一个网页,它的内容状态有一个错误 407,因为代理需要身份验证,并且此页面中指定的代理地址是默认地址,而不是我明确告诉 Qt 的地址使用.

When I run this application I get a web page displayed in WebView whose contents state there is an error 407 because the proxy requires authentication and the proxy address specified in this page is the default one and not the one I am explicitly telling Qt to use.

如何让 Qt 使用我希望它使用的实际代理?这台机器上的所有其他应用程序都可以使用它,为什么不使用 Qt?

How can I get Qt to use the actual proxy I want it to use? All other apps on this machine can use it so why not Qt?

推荐答案

显然 QML WebView 不使用 Qt 代理设置.我不知道这是预期的行为还是只是坏了.尝试按照 本讨论中的建议设置 http_proxy 环境变量.

Apparently QML WebView doesn't use Qt proxy settings. I don't know if this is the expected behavior or it's just broken. Try to set http_proxy environment variable as suggested in this discussion.

这篇关于如何在 Qt 中设置应用程序范围的代理设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆