本文整理汇总了C++中QUrl::query方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::query方法的具体用法?C++ QUrl::query怎么用?C++ QUrl::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AnchorClicked
void OpenLinksFromFileSystem::AnchorClicked(const QUrl & url)
{
#ifdef Q_OS_WIN
if(url.host().contains("shelexecute"))
{
QUrlQuery q;
q.setQuery(url.query());
QString cmd = q.queryItemValue("cmd",QUrl::FullyDecoded);
QString arg = q.queryItemValue("arg",QUrl::FullyDecoded);
LPCWSTR s1 = (LPCWSTR)cmd.utf16();
LPCWSTR s2 = NULL;
if(q.hasQueryItem("arg"))
s2 = (LPCWSTR)arg.utf16();
ShellExecute(NULL,NULL,s1,s2,NULL,SW_RESTORE);
}else
#endif
{
QFileInfo info(url.toString());
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
}
}
示例2: requestPixmap
/*!
* Image {
* source: "image://avatar/path?name=icon-name"
* }
*
* Image {
* source: "image://avatar/path?size=64&name=icon-name"
* }
*/
QPixmap QuickAvatarProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
const QUrl url(QStringLiteral("file:///") + id);
const QUrlQuery query(url.query());
const QString filePath = url.path();
const QString iconName = query.queryItemValue(QStringLiteral("name"));
const QString iconSize = query.queryItemValue(QStringLiteral("size"));
QSize tmp;
if (!size)
size = &tmp;
bool ok = false;
int iconSizeValue = iconSize.toInt(&ok);
if (ok)
*size = QSize(iconSizeValue, iconSizeValue);
else if (requestedSize.width() > 0)
*size = requestedSize;
else
*size = QSize(128, 128);
QIcon icon = Icon(iconName);
if (filePath.size() > 1)
icon = AvatarFilter::icon(filePath, icon);
return icon.pixmap(*size);
}
示例3: testIncludeUrlParams
void Utils::testIncludeUrlParams() {
QUrl urla(QString("http://example.com"));
QHash<QString, QString> params;
params.insert("simple", "c");
params.insert("withspecial", "a?b");
params.insert("withspace", "a b");
params.insert("username", "a123fx b");
params.insert("password", "[email protected]#+-$%^12&*()qweqesaf\"';`~");
params.insert("withplus", "a+b");
QUrl urlb = ::includeQueryParams(urla, params);
QVERIFY(urla.scheme() == urlb.scheme());
QVERIFY(urla.host() == urlb.host());
Q_FOREACH (const QString& key, params.keys()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QString encoded_key = QUrl::toPercentEncoding(key);
QString encoded_value = QUrl::toPercentEncoding(params[encoded_key]);
QUrlQuery query = QUrlQuery(urlb.query());
QVERIFY(query.queryItemValue(encoded_key, QUrl::FullyEncoded) == encoded_value);
#else
QVERIFY(urlb.queryItemValue(key) == params[key]);
#endif
}
}
示例4: openLocalFile
bool OpenLocalHelper::openLocalFile(const QUrl &url)
{
if (url.scheme() != kSeafileProtocolScheme) {
qWarning("[OpenLocalHelper] unknown scheme %s\n", url.scheme().toUtf8().data());
return false;
}
if (url.host() != kSeafileProtocolHostOpenFile) {
qWarning("[OpenLocalHelper] unknown command %s\n", url.host().toUtf8().data());
return false;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QUrlQuery url_query = QUrlQuery(url.query());
QString repo_id = url_query.queryItemValue("repo_id", QUrl::FullyDecoded);
QString email = url_query.queryItemValue("email", QUrl::FullyDecoded);
QString path = url_query.queryItemValue("path", QUrl::FullyDecoded);
#else
QString repo_id = url.queryItemValue("repo_id");
QString email = url.queryItemValue("email");
QString path = url.queryItemValue("path");
#endif
if (repo_id.size() < 36) {
qWarning("[OpenLocalHelper] invalid repo_id %s\n", repo_id.toUtf8().data());
return false;
}
qDebug("[OpenLocalHelper] open local file: repo %s, path %s\n",
repo_id.toUtf8().data(), path.toUtf8().data());
RepoService::instance()->openLocalFile(repo_id, path);
return true;
}
示例5: parseUrl
void RequestParameters::parseUrl(const QUrl & url)
{
if (!url.hasQuery())
{
return;
}
QList<QPair<QString, QVariant >> parameters;
for (const QString & parameter : url.query().split('&'))
{
int splitIndex = parameter.indexOf('=');
if (splitIndex<=0)
{
continue;
}
QString key = parameter.left(splitIndex);
QString value = parameter.mid(splitIndex + 1);
parameters << QPair<QString, QVariant>(key, value);
}
parseList(parameters);
}
示例6: setQueryDelimiters
/*!
Constructs a QUrlQuery object and parses the query string found in the \a
url URL, using the default query delimiters. To parse a query string using
other delimiters, you should first set them using setQueryDelimiters() and
then set the query with setQuery().
\sa QUrl::query()
*/
QUrlQuery::QUrlQuery(const QUrl &url)
: d(0)
{
// use internals to avoid unnecessary recoding
// ### FIXME: actually do it
if (url.hasQuery())
d = new QUrlQueryPrivate(url.query());
}
示例7: handleHTTPRequest
bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {
if (!skipSubHandler && requestHandledByRequestHandler(connection, url)) {
// this request was handled by our request handler object
// so we don't need to attempt to do so in the document root
return true;
}
if (!_documentRoot.isEmpty()) {
// check to see if there is a file to serve from the document root for this path
QString subPath = url.path();
// remove any slash at the beginning of the path
if (subPath.startsWith('/')) {
subPath.remove(0, 1);
}
QString filePath;
if (QFileInfo(_documentRoot + subPath).isFile()) {
filePath = _documentRoot + subPath;
} else if (subPath.size() > 0 && !subPath.endsWith('/')) {
// this could be a directory with a trailing slash
// send a redirect to the path with a slash so we can
QString redirectLocation = '/' + subPath + '/';
if (!url.query().isEmpty()) {
redirectLocation += "?" + url.query();
}
QHash<QByteArray, QByteArray> redirectHeader;
redirectHeader.insert(QByteArray("Location"), redirectLocation.toUtf8());
connection->respond(HTTPConnection::StatusCode301, "", HTTPConnection::DefaultContentType, redirectHeader);
}
// if the last thing is a trailing slash then we want to look for index file
if (subPath.endsWith('/') || subPath.size() == 0) {
QStringList possibleIndexFiles = QStringList() << "index.html" << "index.shtml";
foreach (const QString& possibleIndexFilename, possibleIndexFiles) {
if (QFileInfo(_documentRoot + subPath + possibleIndexFilename).exists()) {
filePath = _documentRoot + subPath + possibleIndexFilename;
break;
}
}
}
示例8: getApiSig
/** Compute MD5 signature using url queries keys and values following Flickr notice:
http://www.flickr.com/services/api/auth.spec.html
*/
QString FlickrTalker::getApiSig(const QString& secret, const QUrl& url)
{
QUrlQuery urlQuery(url.query());
QList<QPair<QString, QString> > temp_queries = urlQuery.queryItems();
QMap<QString, QString> queries;
QPair<QString, QString> pair;
foreach(pair, temp_queries)
{
queries.insert(pair.first,pair.second);
}
示例9: parseBitcoinURI
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
{
// return if URI is not valid or is no sapcoin URI
if(!uri.isValid() || uri.scheme() != QString("sapcoin"))
return false;
SendCoinsRecipient rv;
rv.address = uri.path();
rv.amount = 0;
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery q;
q.setQuery(uri.query());
QList<QPair<QString, QString> > items = q.queryItems();
#else
QList<QPair<QString, QString> > items = uri.queryItems();
#endif
for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
{
bool fShouldReturnFalse = false;
if (i->first.startsWith("req-"))
{
i->first.remove(0, 4);
fShouldReturnFalse = true;
}
if (i->first == "label")
{
rv.label = i->second;
fShouldReturnFalse = false;
}
else if (i->first == "amount")
{
if(!i->second.isEmpty())
{
if(!BitcoinUnits::parse(BitcoinUnits::SAP, i->second, &rv.amount))
{
return false;
}
}
fShouldReturnFalse = false;
}
if (fShouldReturnFalse)
return false;
}
if(out)
{
*out = rv;
}
return true;
}
示例10: toUrl
QUrl ItemFields::toUrl() const {
if (isRemote()) {
QUrl url = QUrl(path().toString());
switch(dataType()) {
case dt_web_sc: {
if (url.query().isEmpty()) // links with hashed policy should not be attachable for additional fields - this action broke policy
url.setQuery(Web::Soundcloud::Queries::obj().genDefaultParams());
break;}
default:;
}
return url;
} else
return QUrl::fromLocalFile(fullPath());
}
示例11: connectToHost
void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QUrl &url)
{
resetConnection(true);
bool useSsl = false;
d->port = 80;
// using proxy?
if(!proxyHost.isEmpty()) {
d->host = proxyHost;
d->port = proxyPort;
d->url = url;
d->use_proxy = true;
}
else {
d->host = url.host();
if(url.port() != -1)
d->port = url.port();
else if (url.scheme() == "https") {
d->port = 443;
useSsl = true;
}
#if QT_VERSION < 0x050000
d->url = url.path() + "?" + url.encodedQuery();
#else
d->url.setUrl(url.path() + "?" + url.query(QUrl::FullyEncoded), QUrl::StrictMode);
#endif
d->use_proxy = false;
}
resetKey();
bool last;
QString key = getKey(&last);
#ifdef PROX_DEBUG
fprintf(stderr, "HttpPoll: Connecting to %s:%d [%s]", d->host.latin1(), d->port, d->url.latin1());
if(d->user.isEmpty())
fprintf(stderr, "\n");
else
fprintf(stderr, ", auth {%s,%s}\n", d->user.latin1(), d->pass.latin1());
#endif
QPointer<QObject> self = this;
syncStarted();
if(!self)
return;
d->state = 1;
d->http.setUseSsl(useSsl);
d->http.setAuth(d->user, d->pass);
d->http.post(d->host, d->port, d->url, makePacket("0", key, "", QByteArray()), d->use_proxy);
}
示例12: urlEncodeQueryString
QString QzTools::urlEncodeQueryString(const QUrl &url)
{
QString returnString = url.toString(QUrl::RemoveQuery | QUrl::RemoveFragment);
if (url.hasQuery()) {
returnString += QLatin1Char('?') + url.query(QUrl::FullyEncoded);
}
if (url.hasFragment()) {
returnString += QLatin1Char('#') + url.fragment(QUrl::FullyEncoded);
}
returnString.replace(QLatin1Char(' '), QLatin1String("%20"));
return returnString;
}
示例13: getAnalyzeRequestData
void DeckStatsInterface::getAnalyzeRequestData(DeckList *deck, QByteArray *data)
{
DeckList deckWithoutTokens;
copyDeckWithoutTokens(*deck, deckWithoutTokens);
#if QT_VERSION < 0x050000
QUrl params;
params.addQueryItem("deck", deckWithoutTokens.writeToString_Plain());
data->append(params.encodedQuery());
#else
QUrl params;
QUrlQuery urlQuery;
urlQuery.addQueryItem("deck", deckWithoutTokens.writeToString_Plain());
params.setQuery(urlQuery);
data->append(params.query(QUrl::EncodeReserved));
#endif
}
示例14: changeCheck
/**
* Checks if connection parameters have changed.
* If it it, close the current connection
*/
void kio_sieveProtocol::changeCheck(const QUrl &url)
{
QString auth;
// Check the SASL auth mechanism in the 'sasl' metadata...
if (!metaData(QStringLiteral("sasl")).isEmpty()) {
auth = metaData(QStringLiteral("sasl")).toUpper();
} else {
// ... and if not found, check the x-mech=AUTH query part of the url.
QString query = url.query();
if (query.startsWith(QLatin1Char('?'))) {
query.remove(0, 1);
}
QStringList q = query.split(QLatin1Char(','));
QStringList::iterator it;
for (it = q.begin(); it != q.end(); ++it) {
if (((*it).section(QLatin1Char('='), 0, 0)).toLower() == QLatin1String("x-mech")) {
auth = ((*it).section(QLatin1Char('='), 1)).toUpper();
break;
}
}
}
ksDebug << "auth: " << auth << " m_sAuth: " << m_sAuth << endl;
if (m_sAuth != auth) {
m_sAuth = auth;
if (isConnected()) {
disconnect();
}
}
// For TLS, only disconnect if we are unencrypted and are
// no longer allowed (otherwise, it's still fine):
const bool allowUnencryptedNow = QUrlQuery(url).queryItemValue(QStringLiteral("x-allow-unencrypted")) == QLatin1String("true");
if (m_allowUnencrypted && !allowUnencryptedNow) {
if (isConnected()) {
disconnect();
}
}
m_allowUnencrypted = allowUnencryptedNow;
}
示例15: setFolderHostsResult
BtsApiNotifier *BtsApi::setFolderHosts(const QString &secret, const QStringList &hosts)
{
QueryList ql;
ql << QueryPair("secret", secret)
<< QueryPair("hosts", hosts.join(','));
QUrl apiUrl = getApiUrl(p, "set_folder_hosts", ql);
QString queryString = apiUrl.query(QUrl::FullyEncoded);
QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
BtsApiNotifier *notifier = new BtsApiNotifier(this);
connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
{
notifier->deleteLater();
if(checkForError(reply, notifier))
return;
QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
if(checkForError(doc, notifier))
return;
QJsonObject obj = doc.object();
QJsonArray arr = obj.value("hosts").toArray();
QStringList res;
for(const QJsonValue &val: arr)
res << val.toString();
emit setFolderHostsResult(res, secret);
emit notifier->setFolderHostsResult(res, secret);
});
return notifier;
}