当前位置: 首页>>代码示例>>C++>>正文


C++ QNetworkProxyQuery::setUrl方法代码示例

本文整理汇总了C++中QNetworkProxyQuery::setUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkProxyQuery::setUrl方法的具体用法?C++ QNetworkProxyQuery::setUrl怎么用?C++ QNetworkProxyQuery::setUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QNetworkProxyQuery的用法示例。


在下文中一共展示了QNetworkProxyQuery::setUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_connectBtn_clicked

void MainWindow::on_connectBtn_clicked()
{
    VpnInfo *vpninfo = NULL;
    StoredServer *ss = new StoredServer(this->settings);
    QFuture < void >future;
    QString name, str, url;
    QList < QNetworkProxy > proxies;
    QUrl turl;
    QNetworkProxyQuery query;

    if (ui->connectBtn->isEnabled() == false) {
        return;
    }

    if (this->cmd_fd != INVALID_SOCKET) {
        QMessageBox::information(this,
                                 tr(APP_NAME),
                                 tr
                                 ("A previous VPN instance is still running (socket is active)"));
        return;
    }

    if (this->futureWatcher.isRunning() == true) {
        QMessageBox::information(this,
                                 tr(APP_NAME),
                                 tr
                                 ("A previous VPN instance is still running"));
        return;
    }

    if (ui->comboBox->currentText().isEmpty()) {
        QMessageBox::information(this,
                                 tr(APP_NAME),
                                 tr
                                 ("You need to specify a gateway. E.g. vpn.example.com:443"));
        return;
    }

    name = ui->comboBox->currentText();
    ss->load(name);
    turl.setUrl("https://" + ss->get_servername());
    query.setUrl(turl);

    /* ss is now deallocated by vpninfo */
    vpninfo = new VpnInfo(tr(APP_STRING), ss, this);
    if (vpninfo == NULL) {
        QMessageBox::information(this,
                                 tr(APP_NAME),
                                 tr
                                 ("There was an issue initializing the VPN."));
        goto fail;
    }

    this->minimize_on_connect = vpninfo->get_minimize();

    vpninfo->parse_url(ss->get_servername().toLocal8Bit().data());

    this->cmd_fd = vpninfo->get_cmd_fd();
    if (this->cmd_fd == INVALID_SOCKET) {
        QMessageBox::information(this,
                                 tr(APP_NAME),
                                 tr
                                 ("There was an issue establishing IPC with openconnect; try restarting the application."));
        goto fail;
    }

    proxies = QNetworkProxyFactory::systemProxyForQuery(query);
    if (proxies.size() > 0 && proxies.at(0).type() != QNetworkProxy::NoProxy) {
        if (proxies.at(0).type() == QNetworkProxy::Socks5Proxy)
            url = "socks5://";
        else if (proxies.at(0).type() == QNetworkProxy::HttpCachingProxy
                 || proxies.at(0).type() == QNetworkProxy::HttpProxy)
            url = "http://";

        if (url.isEmpty() == false) {

            str =
                proxies.at(0).user() + ":" + proxies.at(0).password() + "@" +
                proxies.at(0).hostName();
            if (proxies.at(0).port() != 0) {
                str += ":" + QString::number(proxies.at(0).port());
            }
            this->updateProgressBar(tr("Setting proxy to: ") + str);
            openconnect_set_http_proxy(vpninfo->vpninfo, str.toAscii().data());
        }
    }

    future = QtConcurrent::run(main_loop, vpninfo, this);

    this->futureWatcher.setFuture(future);

    return;
 fail:
    if (vpninfo != NULL)
        delete vpninfo;
    return;
}
开发者ID:Sindisil,项目名称:openconnect-gui,代码行数:97,代码来源:mainwindow.cpp


注:本文中的QNetworkProxyQuery::setUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。