本文整理汇总了C++中QUrlQuery::setQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrlQuery::setQuery方法的具体用法?C++ QUrlQuery::setQuery怎么用?C++ QUrlQuery::setQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrlQuery
的用法示例。
在下文中一共展示了QUrlQuery::setQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: old_queryItems
void tst_QUrlQuery::old_queryItems()
{
// test imported from old tst_qurl.cpp
QUrlQuery url;
QList<QPair<QString, QString> > newItems;
newItems += qMakePair(QString("1"), QString("a"));
newItems += qMakePair(QString("2"), QString("b"));
newItems += qMakePair(QString("3"), QString("c"));
newItems += qMakePair(QString("4"), QString("a b"));
newItems += qMakePair(QString("5"), QString("&"));
newItems += qMakePair(QString("foo bar"), QString("hello world"));
newItems += qMakePair(QString("foo+bar"), QString("hello+world"));
newItems += qMakePair(QString("tex"), QString("a + b = c"));
url.setQueryItems(newItems);
QVERIFY(!url.isEmpty());
QList<QPair<QString, QString> > setItems = url.queryItems();
QVERIFY(newItems == setItems);
url.addQueryItem("1", "z");
#if 0
// undefined behaviour in the new QUrlQuery
QVERIFY(url.hasQueryItem("1"));
QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "a");
url.addQueryItem("1", "zz");
QStringList expected;
expected += "a";
expected += "z";
expected += "zz";
QCOMPARE(url.allQueryItemValues("1"), expected);
url.removeQueryItem("1");
QCOMPARE(url.allQueryItemValues("1").size(), 2);
QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "z");
#endif
url.removeAllQueryItems("1");
QVERIFY(!url.hasQueryItem("1"));
QCOMPARE(url.queryItemValue("4").toLatin1().constData(), "a b");
QCOMPARE(url.queryItemValue("5").toLatin1().constData(), "&");
QCOMPARE(url.queryItemValue("tex").toLatin1().constData(), "a + b = c");
QCOMPARE(url.queryItemValue("foo bar").toLatin1().constData(), "hello world");
//url.setUrl("http://www.google.com/search?q=a+b");
url.setQuery("q=a+b");
QCOMPARE(url.queryItemValue("q"), QString("a+b"));
//url.setUrl("http://www.google.com/search?q=a=b"); // invalid, but should be tolerated
url.setQuery("q=a=b");
QCOMPARE(url.queryItemValue("q"), QString("a=b"));
}
示例2: 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()));
}
}
示例3: 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;
}
示例4: differentDelimiters
void tst_QUrlQuery::differentDelimiters()
{
QUrlQuery query;
query.setQueryDelimiters('(', ')');
{
// parse:
query.setQuery("foo(bar)hello(world)");
QueryItems expected;
expected << qItem("foo", "bar") << qItem("hello", "world");
COMPARE_ITEMS(query.queryItems(), expected);
COMPARE_ITEMS(query.queryItems(QUrl::FullyEncoded), expected);
COMPARE_ITEMS(query.queryItems(QUrl::PrettyDecoded), expected);
}
{
// reconstruct:
// note the final ')' is missing because there are no further items
QCOMPARE(query.query(), QString("foo(bar)hello(world"));
}
{
// set items containing the new delimiters and the old ones
query.clear();
query.addQueryItem("z(=)", "y(&)");
QCOMPARE(query.query(), QString("z%28=%29(y%28&%29"));
QUrlQuery copy = query;
QCOMPARE(query.query(), QString("z%28=%29(y%28&%29"));
copy.setQueryDelimiters(QUrlQuery::defaultQueryValueDelimiter(),
QUrlQuery::defaultQueryPairDelimiter());
QCOMPARE(copy.query(), QString("z(%3D)=y(%26)"));
}
}
示例5: openUrl
bool WulforUtil::openUrl(const QString &url){
if (url.startsWith("http://") || url.startsWith("www.") || url.startsWith(("ftp://")) || url.startsWith("https://")){
if (!SETTING(MIME_HANDLER).empty())
QProcess::startDetached(_q(SETTING(MIME_HANDLER)), QStringList(url));
else
QDesktopServices::openUrl(QUrl::fromEncoded(url.toUtf8()));
}
else if (url.startsWith("adc://") || url.startsWith("adcs://")){
MainWindow::getInstance()->newHubFrame(url, "UTF-8");
}
else if (url.startsWith("dchub://") || url.startsWith("nmdcs://")){
MainWindow::getInstance()->newHubFrame(url, WSGET(WS_DEFAULT_LOCALE));
}
else if (url.startsWith("magnet:") && url.contains("urn:tree:tiger")){
QString magnet = url;
Magnet *m = new Magnet(MainWindow::getInstance());
m->setLink(magnet);
m->exec();
m->deleteLater();
}
else if (url.startsWith("magnet:")){
const QString magnet = url;
#if QT_VERSION >= 0x050000
QUrlQuery u;
#else
QUrl u;
#endif
if (!magnet.contains("+")) {
#if QT_VERSION >= 0x050000
u.setQuery(magnet.toUtf8());
#else
u.setEncodedUrl(magnet.toUtf8());
#endif
} else {
QString _l = magnet;
_l.replace("+", "%20");
#if QT_VERSION >= 0x050000
u.setQuery(_l.toUtf8());
#else
u.setEncodedUrl(_l.toUtf8());
#endif
}
if (u.hasQueryItem("kt")) {
QString keywords = u.queryItemValue("kt");
QString hub = u.hasQueryItem("xs")? u.queryItemValue("xs") : "";
if (!(hub.startsWith("dchub://", Qt::CaseInsensitive) ||
hub.startsWith("nmdcs://", Qt::CaseInsensitive) ||
hub.startsWith("adc://", Qt::CaseInsensitive) ||
hub.startsWith("adcs://", Qt::CaseInsensitive)) && !hub.isEmpty())
hub.prepend("dchub://");
if (keywords.isEmpty())
return false;
if (!hub.isEmpty())
WulforUtil::openUrl(hub);
SearchFrame *sfr = ArenaWidgetFactory().create<SearchFrame>();
sfr->fastSearch(keywords, false);
}
else {
if (!SETTING(MIME_HANDLER).empty())
QProcess::startDetached(_q(SETTING(MIME_HANDLER)), QStringList(url));
else
QDesktopServices::openUrl(QUrl::fromEncoded(url.toUtf8()));
}
}
else
return false;
return true;
}