本文整理汇总了C++中QUrl::setPort方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::setPort方法的具体用法?C++ QUrl::setPort怎么用?C++ QUrl::setPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::setPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup(const QUrl &_uri, const HttpHeaders &_headers, const QHostAddress &connectAddr = QHostAddress(), int connectPort = -1, int _maxRedirects = -1, const QString &connectHostToTrust = QString())
{
assert(!method.isEmpty());
QUrl uri = _uri;
if(connectPort != -1)
uri.setPort(connectPort);
else if(uri.port() == -1)
{
if(uri.scheme() == "https")
uri.setPort(443);
else
uri.setPort(80);
}
HttpHeaders headers = _headers;
checkHosts += uri.host(QUrl::FullyEncoded);
if(!connectAddr.isNull())
{
curl_slist_free_all(dnsCache);
if(!connectHostToTrust.isEmpty())
checkHosts += connectHostToTrust;
QByteArray cacheEntry = uri.host(QUrl::FullyEncoded).toUtf8() + ':' + QByteArray::number(uri.port()) + ':' + connectAddr.toString().toUtf8();
dnsCache = curl_slist_append(dnsCache, cacheEntry.data());
curl_easy_setopt(easy, CURLOPT_RESOLVE, dnsCache);
}
curl_easy_setopt(easy, CURLOPT_URL, uri.toEncoded().data());
bool chunked = false;
if(headers.contains("Content-Length"))
{
curl_off_t content_len = (curl_off_t)headers.get("Content-Length").toLongLong();
/*if(method == "POST")
curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE_LARGE, content_len);
else*/
curl_easy_setopt(easy, CURLOPT_INFILESIZE_LARGE, content_len);
// curl will set this for us
headers.removeAll("Content-Length");
}
else
{
if(expectBody)
chunked = true;
else if(alwaysSetBody)
curl_easy_setopt(easy, CURLOPT_INFILESIZE_LARGE, (curl_off_t)0);
}
curl_slist_free_all(headersList);
foreach(const HttpHeader &h, headers)
{
QByteArray i = h.first + ": " + h.second;
headersList = curl_slist_append(headersList, i.data());
}
示例2: if
QUrl
ContentTreeView::ContentNode2QUrl(ContentNode *node)
{
QUrl u;
if (node->is_group()) {
u.setPort(node->type());
u.setPath(QString::fromStdString(node->ParseAsGroup()->title()));
} else if (node->is_layer()) {
u.setPort(node->type());
u.setPath(QString::fromStdString(node->ParseAsLayer()->path()));
} else {
// undefined
}
return u;
}
示例3: stream
void RtspSocket::stream(QUrl url,QString chid, bool aud)
{
qDebug("Start Streaming");
audioEnabled = aud;
channelid = chid;
if(url.port() == -1 || url.port()==0 )
url.setPort(554);
QDEBUG << url.toString();
qWarning() << tr("Stream: ") + url.toString();
if( state == statePlay || state == statePlaying || state == stateTeardown )
{
state = stateTeardown;
// set this after the teardown message
_url = url;
} else
{
_url = url;
// restart the state machine
state = stateInit;
}
slotStateMachine();
}
示例4: url
CddbConnection(cddb_disc_t *d) : disc(0) {
connection = cddb_new();
if (connection) {
cddb_cache_disable(connection);
cddb_set_server_name(connection, Settings::self()->cddbHost().toLatin1().constData());
cddb_set_server_port(connection, Settings::self()->cddbPort());
disc=cddb_disc_clone(d);
#ifdef ENABLE_KDE_SUPPORT
QString proxy=KProtocolManager::proxyFor("http");
if (!proxy.isEmpty()) {
QUrl url(proxy);
cddb_set_http_proxy_server_name(connection, url.host().toLatin1().constData());
cddb_set_http_proxy_server_port(connection, url.port());
cddb_http_proxy_enable(connection);
}
#else
QUrl url;
url.setHost(Settings::self()->cddbHost());
url.setPort(Settings::self()->cddbPort());
QList<QNetworkProxy> proxies=NetworkProxyFactory::self()->queryProxy(QNetworkProxyQuery(url));
foreach (const QNetworkProxy &p, proxies) {
if (QNetworkProxy::HttpProxy==p.type() && 0!=p.port()) {
cddb_set_http_proxy_server_name(connection, p.hostName().toLatin1().constData());
cddb_set_http_proxy_server_port(connection, p.port());
cddb_http_proxy_enable(connection);
break;
}
}
#endif
}
}
示例5: webPageSelected
void WebInspectorWidget::webPageSelected(int index)
{
QObject *obj = ui->webPageComboBox->itemData(index, ObjectModel::ObjectRole).value<QObject*>();
// Wk 1, local
if (QWebPage *page = qobject_cast<QWebPage*>(obj)) {
page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
ui->webInspector->setPage(page);
// webinspector needs a show event to actually show anything, just setting the page is not enough...
ui->webInspector->hide();
ui->webInspector->show();
ui->stack->setCurrentWidget(ui->wk1LocalPage);
}
else if (ui->webPageComboBox->itemData(index, WebViewModel::WebKitVersionRole).toInt() == 2) {
const QUrl serverUrl = Endpoint::instance()->serverAddress();
if (serverUrl.scheme() == QLatin1String("tcp")) {
QUrl inspectorUrl;
inspectorUrl.setScheme(QStringLiteral("http"));
inspectorUrl.setHost(serverUrl.host());
inspectorUrl.setPort(Endpoint::defaultPort() + 1);
ui->webView->setUrl(inspectorUrl);
ui->stack->setCurrentWidget(ui->wk2Page);
}
}
// WK1, remote
else {
ui->stack->setCurrentWidget(ui->wk1RemotePage);
}
}
示例6: slotAuthenticationRequired
void AccessManager::slotAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
{
#ifndef TOKEN_AUTH_ONLY
// do not handle 401 created by the networkjobs. We may want
// to eventually exempt some, but for now we need
// it only for other things, e.g. the browser. Would we handle
// network jobs, this would break the wizard logic
if (reply->property("doNotHandleAuth").toBool()) {
return;
}
QUrl url = reply->url();
// show only scheme, host and port
QUrl reducedUrl;
reducedUrl.setScheme(url.scheme());
reducedUrl.setHost(url.host());
reducedUrl.setPort(url.port());
AuthenticationDialog dialog(authenticator->realm(), reducedUrl.toString());
if (dialog.exec() == QDialog::Accepted) {
authenticator->setUser(dialog.user());
authenticator->setPassword(dialog.password());
}
#else
Q_UNUSED(reply) Q_UNUSED(authenticator)
Q_ASSERT(!"OCC::AccessManager::slotAuthenticationRequired called");
#endif
}
示例7: open
void QNetworkAccessHttpBackend::open()
{
QUrl url = request().url();
bool encrypt = url.scheme() == QLatin1String("https");
setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, encrypt);
// set the port number in the reply if it wasn't set
url.setPort(url.port(encrypt ? DefaultHttpsPort : DefaultHttpPort));
// check if we have an open connection to this host
QByteArray cacheKey = makeCacheKey(this->url());
QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this);
if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) {
// no entry in cache; create an object
http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt);
#ifndef QT_NO_NETWORKPROXY
QNetworkProxy networkProxy = proxy();
if (encrypt || networkProxy.type() == QNetworkProxy::HttpProxy)
http->setTransparentProxy(networkProxy);
else
http->setCacheProxy(networkProxy);
#endif
cache->addEntry(cacheKey, http);
}
setupConnection();
postRequest();
}
示例8: QString
KJob *UPnPRouter::sendSoapQuery(const QString & query,const QString & soapact,const QString & controlurl)
{
// if port is not set, 0 will be returned
// thanks to Diego R. Brogna for spotting this bug
if (location.port()<=0)
location.setPort(80);
QUrl address;
address.setScheme(QString("http"));
address.setHost(location.host());
address.setPort(location.port());
address.setPath(controlurl);
KIO::TransferJob *req = KIO::http_post( address, query.toLatin1(), KIO::HideProgressInfo );
req->addMetaData("content-type", QString("text/xml"));
req->addMetaData("UserAgent", QString("Konversation UPnP"));
req->addMetaData("customHTTPHeader", QString("SOAPAction: ") + soapact);
soap_data_out[req] = QByteArray();
soap_data_in[req] = QByteArray();
connect(req, &KIO::TransferJob::data, this, &UPnPRouter::recvSoapData);
connect(req, &KIO::TransferJob::dataReq, this, &UPnPRouter::sendSoapData);
connect(req, &KIO::TransferJob::result, this, &UPnPRouter::onRequestFinished);
return req;
}
示例9: getCurrentUrl
void MumbleDBus::getCurrentUrl(const QDBusMessage &msg) {
if (!g.sh || !g.sh->isRunning() || ! g.uiSession) {
QDBusConnection::sessionBus().send(msg.createErrorReply(QLatin1String("net.sourceforge.mumble.Error.connection"), QLatin1String("Not connected")));
return;
}
QString host, user, pw;
unsigned short port;
QUrl u;
g.sh->getConnectionInfo(host, port, user, pw);
u.setScheme(QLatin1String("mumble"));
u.setHost(host);
u.setPort(port);
u.setUserName(user);
#if QT_VERSION >= 0x050000
QUrlQuery query;
query.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
u.setQuery(query);
#else
u.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
#endif
QStringList path;
Channel *c = ClientUser::get(g.uiSession)->cChannel;
while (c->cParent) {
path.prepend(c->qsName);
c = c->cParent;
}
u.setPath(path.join(QLatin1String("/")));
QDBusConnection::sessionBus().send(msg.createReply(QString::fromLatin1(u.toEncoded())));
}
示例10: setRubyProxyEnvironment
void PatMainWindow::setRubyProxyEnvironment(const QNetworkProxy &t_proxy)
{
OS_ASSERT(t_proxy.type() == QNetworkProxy::NoProxy || t_proxy.type() == QNetworkProxy::HttpProxy);
if (t_proxy.type() == QNetworkProxy::NoProxy)
{
LOG(Info, "Clearing proxy environment variables");
bool set = qputenv("HTTP_PROXY", QByteArray());
OS_ASSERT(set);
set = qputenv("HTTP_PROXY_USER", QByteArray());
OS_ASSERT(set);
set = qputenv("HTTP_PROXY_PASS", QByteArray());
OS_ASSERT(set);
set = qputenv("HTTP_USER", QByteArray());
OS_ASSERT(set);
set = qputenv("HTTP_PASS", QByteArray());
OS_ASSERT(set);
} else if (t_proxy.type() == QNetworkProxy::HttpProxy) {
LOG(Info, "Clearing proxy environment variables");
QUrl urlsimple;
urlsimple.setHost(t_proxy.hostName());
urlsimple.setPort(t_proxy.port());
urlsimple.setScheme("http");
bool set = qputenv("HTTP_PROXY", urlsimple.toString().toLatin1());
OS_ASSERT(set);
set = qputenv("HTTP_PROXY_USER", t_proxy.user().toLatin1());
OS_ASSERT(set);
set = qputenv("HTTP_PROXY_PASS", t_proxy.password().toLatin1());
OS_ASSERT(set);
set = qputenv("HTTP_USER", t_proxy.user().toLatin1());
OS_ASSERT(set);
set = qputenv("HTTP_PASS", t_proxy.password().toLatin1());
OS_ASSERT(set);
}
}
示例11: Init
void TcpAddress::Init(const QString &ip, int port)
{
bool valid = true;
if(port < 0 || port > 65535) {
qWarning() << "Invalid port:" << port;
valid = false;
}
QHostAddress host(ip);
if(host.toString() != ip) {
qWarning() << "Invalid IP:" << ip;
valid = false;
}
if(host == QHostAddress::Null) {
host = QHostAddress::Any;
}
QUrl url;
url.setScheme(Scheme);
url.setHost(ip);
url.setPort(port);
_data = new TcpAddressData(url, host, port, valid);
}
示例12: getApiUrl
static QUrl getApiUrl(BtsApi_private *p, const QString &method, const QueryList &querylist = QueryList())
{
assertClient(p);
QUrl res;
res.setScheme("http");
res.setHost(p->client->getHost());
res.setPort(p->client->getPort());
if(!p->client->getUserName().isEmpty())
res.setUserName(p->client->getUserName());
if(!p->client->getPassword().isEmpty())
res.setPassword(p->client->getPassword());
res.setPath("/api");
QUrlQuery urlQuery;
urlQuery.addQueryItem("method", method);
for(const QueryPair &qp: querylist)
{
if(qp.second.isNull())
urlQuery.addQueryItem(qp.first, "");
else
urlQuery.addQueryItem(qp.first, qp.second);
}
res.setQuery(urlQuery);
return res;
}
示例13: TestMakeParser
void TsFactory::TestMakeParser()
{
try
{
//test postgis uri
QUrl postgisUri;
postgisUri.setScheme("postgis");
postgisUri.setHost("localhost");
postgisUri.setPort(5432);
postgisUri.setUserName("postgres");
postgisUri.setPassword("postgres");
postgisUri.setPath("/basedeteste");
terrama2::core::DataSetItem unknownTypeItem(terrama2::core::DataSetItem::UNKNOWN_TYPE);
//FIXME: create a DataSetItem kind for ParserPostgis
// terrama2::collector::ParserPtr parser = terrama2::collector::Factory::makeParser(unknownTypeItem);
// terrama2::collector::ParserPostgis* parserPostgis = dynamic_cast<terrama2::collector::ParserPostgis*>(parser.get());
// QVERIFY(parserPostgis);
QUrl fileUri;
fileUri.setScheme("file");
fileUri.setPath("/tmp");
terrama2::collector::ParserPtr parser = terrama2::collector::Factory::makeParser(unknownTypeItem);
terrama2::collector::ParserOGR* parserOGR = dynamic_cast<terrama2::collector::ParserOGR*>(parser.get());
QVERIFY(parserOGR);
terrama2::core::DataSetItem pcdInpeTypeItem(terrama2::core::DataSetItem::PCD_INPE_TYPE);
parser = terrama2::collector::Factory::makeParser(pcdInpeTypeItem);
terrama2::collector::ParserPcdInpe* parserPdcInpe = dynamic_cast<terrama2::collector::ParserPcdInpe*>(parser.get());
QVERIFY(parserPdcInpe);
terrama2::core::DataSetItem pcdToaTypeItem(terrama2::core::DataSetItem::PCD_TOA5_TYPE);
parser = terrama2::collector::Factory::makeParser(pcdToaTypeItem);
terrama2::collector::ParserPcdToa5* parserPdctoa5 = dynamic_cast<terrama2::collector::ParserPcdToa5*>(parser.get());
QVERIFY(parserPdctoa5);
terrama2::core::DataSetItem firePointTypeItem(terrama2::core::DataSetItem::FIRE_POINTS_TYPE);
parser = terrama2::collector::Factory::makeParser(firePointTypeItem);
terrama2::collector::ParserFirePoint* parserFirePoint = dynamic_cast<terrama2::collector::ParserFirePoint*>(parser.get());
QVERIFY(parserFirePoint);
try
{
terrama2::core::DataSetItem diseaseTypeItem(terrama2::core::DataSetItem::DISEASE_OCCURRENCE_TYPE);
parser = terrama2::collector::Factory::makeParser(diseaseTypeItem);
QFAIL(NO_EXCEPTION_THROWN);
}
catch(terrama2::collector::ConflictingParserTypeSchemeException& e)
{
}
}
catch(...)
{
QFAIL(NO_EXCEPTION_EXPECTED);
}
}
示例14: makeCacheKey
static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy)
{
QString result;
QUrl copy = url;
QString scheme = copy.scheme().toLower();
bool isEncrypted = scheme == QLatin1String("https");
copy.setPort(copy.port(isEncrypted ? 443 : 80));
if (scheme == QLatin1String("preconnect-http")) {
copy.setScheme(QLatin1String("http"));
} else if (scheme == QLatin1String("preconnect-https")) {
copy.setScheme(QLatin1String("https"));
}
result = copy.toString(QUrl::RemoveUserInfo | QUrl::RemovePath |
QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::FullyEncoded);
#ifndef QT_NO_NETWORKPROXY
if (proxy && proxy->type() != QNetworkProxy::NoProxy) {
QUrl key;
switch (proxy->type()) {
case QNetworkProxy::Socks5Proxy:
key.setScheme(QLatin1String("proxy-socks5"));
break;
case QNetworkProxy::HttpProxy:
case QNetworkProxy::HttpCachingProxy:
key.setScheme(QLatin1String("proxy-http"));
break;
default:
break;
}
if (!key.scheme().isEmpty()) {
key.setUserName(proxy->user());
key.setHost(proxy->hostName());
key.setPort(proxy->port());
key.setQuery(result);
result = key.toString(QUrl::FullyEncoded);
}
}
#else
Q_UNUSED(proxy)
#endif
return "http-connection:" + result.toLatin1();
}
示例15: TestOKDownloadFile
void TsDataRetrieverFTP::TestOKDownloadFile()
{
try
{
QUrl url;
url.setHost("ftp.dgi.inpe.br");
url.setPath("/focos_operacao/");
url.setScheme("FTP");
url.setPort(21);
url.setUserName("queimadas");
url.setPassword("inpe_2012");
curl_global_init(CURL_GLOBAL_ALL);
//DataProvider information
terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
dataProvider->uri = url.url().toStdString();
dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
dataProvider->dataProviderType = "FTP";
dataProvider->active = true;
//empty filter
terrama2::core::Filter filter;
std::string path;
std::string mask = "exporta_20160501_0230.csv";
MockCurlWrapper mock_;
ON_CALL(mock_, verifyURL(_)).WillByDefault(Return(CURLE_OK));
ON_CALL(mock_, getDownloadFiles(_,_,_)).WillByDefault(Return(CURLE_OK));
try
{
terrama2::core::DataRetrieverFTP retrieverFTP(dataProviderPtr, std::move(mock_));
auto remover = std::make_shared<terrama2::core::FileRemover>();
path = retrieverFTP.retrieveData(mask, filter, remover);
}
catch(...)
{
QFAIL("Unexpected exception!");
}
curl_global_cleanup();
}
catch(const terrama2::Exception& e)
{
QFAIL(boost::get_error_info< terrama2::ErrorDescription >(e)->toStdString().c_str());
}
catch(...)
{
QFAIL("Unexpected exception!");
}
return;
}