本文整理汇总了C++中QUrlQuery::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrlQuery::isEmpty方法的具体用法?C++ QUrlQuery::isEmpty怎么用?C++ QUrlQuery::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrlQuery
的用法示例。
在下文中一共展示了QUrlQuery::isEmpty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multiAddRemove
void tst_QUrlQuery::multiAddRemove()
{
QUrlQuery query;
{
// one item, two values
query.addQueryItem("a", "b");
query.addQueryItem("a", "c");
QVERIFY(!query.isEmpty());
QVERIFY(query.hasQueryItem("a"));
// returns the first one
QVERIFY(query.queryItemValue("a") == "b");
// order is the order we set them in
QVERIFY(query.allQueryItemValues("a") == QStringList() << "b" << "c");
}
{
// add another item, two values
query.addQueryItem("A", "B");
query.addQueryItem("A", "C");
QVERIFY(query.hasQueryItem("A"));
QVERIFY(query.hasQueryItem("a"));
QVERIFY(query.queryItemValue("a") == "b");
QVERIFY(query.allQueryItemValues("a") == QStringList() << "b" << "c");
QVERIFY(query.queryItemValue("A") == "B");
QVERIFY(query.allQueryItemValues("A") == QStringList() << "B" << "C");
}
{
// remove one of the original items
query.removeQueryItem("a");
QVERIFY(query.hasQueryItem("a"));
// it must have removed the first one
QVERIFY(query.queryItemValue("a") == "c");
}
{
// remove the items we added later
query.removeAllQueryItems("A");
QVERIFY(!query.isEmpty());
QVERIFY(!query.hasQueryItem("A"));
}
{
// add one element to the current, then remove them
query.addQueryItem("a", "d");
query.removeAllQueryItems("a");
QVERIFY(!query.hasQueryItem("a"));
QVERIFY(query.isEmpty());
}
}
示例2: 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"));
}
示例3: Get
//******************************************************************************************
//function: doGet
//params: const QHash<QString, QString> ¶meters
//return: QJsonObject
//Description:
//******************************************************************************************
QJsonObject WSClient::Get(const QString &operation, const QHash<QString, QString> ¶meters)
{
QJsonObject response;
QUrlQuery values;
values.addQueryItem("operation", operation);
if (!this->lpzSessionId.isEmpty())
values.addQueryItem("sessionName", this->lpzSessionId);
QHashIterator<QString, QString> params(parameters);
while(params.hasNext()) {
params.next();
values.addQueryItem(params.key(), params.value());
}
if(!values.isEmpty()) {
QUrl url ( this->lpzURL );
url.setQuery(values.query());
if(url.isValid()) {
QJsonObject result = this->doGet(url);
#ifdef QT_DEBUG
//qDebug() << result;
#endif
if ( !result.isEmpty() ) {
return result;
}
else {
QJsonObject error;
error["code"] = "General";
error["message"] = "No data";
throw WSClientException( response );
}
}
}
return response;
}
示例4: execute
void YoutubeProtocolHandler::execute(const QUrl &uri, bool queue)
{
QStringList parts = uri.path().split('/');
QUrlQuery query;
if (parts.count()) {
query.addQueryItem("action", "play_video");
query.addQueryItem("videoid", parts.last());
}
if (query.isEmpty()) {
return;
}
PlaylistItem item;
item.setFile("plugin://plugin.video.youtube/?" + query.toString());
Player *player = Kodi::instance()->videoPlayer();
if (queue) {
player->playlist()->addItems(item);
} else {
player->open(item);
}
}
示例5: addRemove
void tst_QUrlQuery::addRemove()
{
QUrlQuery query;
{
// one item
query.addQueryItem("a", "b");
QVERIFY(!query.isEmpty());
QVERIFY(query.hasQueryItem("a"));
QCOMPARE(query.queryItemValue("a"), QString("b"));
QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b");
QList<QPair<QString, QString> > allItems = query.queryItems();
QCOMPARE(allItems.count(), 1);
QCOMPARE(allItems.at(0).first, QString("a"));
QCOMPARE(allItems.at(0).second, QString("b"));
}
QUrlQuery original = query;
{
// two items
query.addQueryItem("c", "d");
QVERIFY(query.hasQueryItem("a"));
QCOMPARE(query.queryItemValue("a"), QString("b"));
QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b");
QVERIFY(query.hasQueryItem("c"));
QCOMPARE(query.queryItemValue("c"), QString("d"));
QCOMPARE(query.allQueryItemValues("c"), QStringList() << "d");
QList<QPair<QString, QString> > allItems = query.queryItems();
QCOMPARE(allItems.count(), 2);
QVERIFY(allItems.contains(qItem("a", "b")));
QVERIFY(allItems.contains(qItem("c", "d")));
QVERIFY(query != original);
QVERIFY(!(query == original));
}
{
// remove an item that isn't there
QUrlQuery copy = query;
query.removeQueryItem("e");
QCOMPARE(query, copy);
}
{
// remove an item
query.removeQueryItem("c");
QVERIFY(query.hasQueryItem("a"));
QCOMPARE(query.queryItemValue("a"), QString("b"));
QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b");
QList<QPair<QString, QString> > allItems = query.queryItems();
QCOMPARE(allItems.count(), 1);
QCOMPARE(allItems.at(0).first, QString("a"));
QCOMPARE(allItems.at(0).second, QString("b"));
QVERIFY(query == original);
QVERIFY(!(query != original));
}
{
// add an item with en empty value
QString emptyButNotNull(0, Qt::Uninitialized);
QVERIFY(emptyButNotNull.isEmpty());
QVERIFY(!emptyButNotNull.isNull());
query.addQueryItem("e", "");
QVERIFY(query.hasQueryItem("a"));
QCOMPARE(query.queryItemValue("a"), QString("b"));
QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b");
QVERIFY(query.hasQueryItem("e"));
QCOMPARE(query.queryItemValue("e"), emptyButNotNull);
QCOMPARE(query.allQueryItemValues("e"), QStringList() << emptyButNotNull);
QList<QPair<QString, QString> > allItems = query.queryItems();
QCOMPARE(allItems.count(), 2);
QVERIFY(allItems.contains(qItem("a", "b")));
QVERIFY(allItems.contains(qItem("e", emptyButNotNull)));
QVERIFY(query != original);
QVERIFY(!(query == original));
}
{
// remove the items
query.removeQueryItem("a");
query.removeQueryItem("e");
QVERIFY(query.isEmpty());
}
}
示例6: constructing
void tst_QUrlQuery::constructing()
{
QUrlQuery empty;
QVERIFY(empty.isEmpty());
QCOMPARE(empty.queryPairDelimiter(), QUrlQuery::defaultQueryPairDelimiter());
QCOMPARE(empty.queryValueDelimiter(), QUrlQuery::defaultQueryValueDelimiter());
// undefined whether it is detached, but don't crash
QVERIFY(empty.isDetached() || !empty.isDetached());
empty.clear();
QVERIFY(empty.isEmpty());
{
QUrlQuery copy(empty);
QVERIFY(copy.isEmpty());
QVERIFY(!copy.isDetached());
QVERIFY(copy == empty);
QVERIFY(!(copy != empty));
copy = empty;
QVERIFY(copy == empty);
copy = QUrlQuery();
QVERIFY(copy == empty);
}
{
QUrlQuery copy(emptyQuery());
QVERIFY(copy == empty);
}
QVERIFY(!empty.hasQueryItem("a"));
QVERIFY(empty.queryItemValue("a").isEmpty());
QVERIFY(empty.allQueryItemValues("a").isEmpty());
QVERIFY(!empty.hasQueryItem(""));
QVERIFY(empty.queryItemValue("").isEmpty());
QVERIFY(empty.allQueryItemValues("").isEmpty());
QVERIFY(!empty.hasQueryItem(QString()));
QVERIFY(empty.queryItemValue(QString()).isEmpty());
QVERIFY(empty.allQueryItemValues(QString()).isEmpty());
QVERIFY(empty.queryItems().isEmpty());
QUrlQuery other;
other.addQueryItem("a", "b");
QVERIFY(!other.isEmpty());
QVERIFY(other.isDetached());
QVERIFY(other != empty);
QVERIFY(!(other == empty));
QUrlQuery copy(other);
QVERIFY(copy == other);
copy.clear();
QVERIFY(copy.isEmpty());
QVERIFY(copy != other);
copy = other;
QVERIFY(!copy.isEmpty());
QVERIFY(copy == other);
copy = QUrlQuery();
QVERIFY(copy.isEmpty());
empty.setQueryDelimiters('(', ')');
QCOMPARE(empty.queryValueDelimiter(), QChar(QLatin1Char('(')));
QCOMPARE(empty.queryPairDelimiter(), QChar(QLatin1Char(')')));
QList<QPair<QString, QString> > query;
query += qMakePair(QString("type"), QString("login"));
query += qMakePair(QString("name"), QString::fromUtf8("åge nissemannsen"));
query += qMakePair(QString("ole&du"), QString::fromUtf8("anne+jørgen=sant"));
query += qMakePair(QString("prosent"), QString("%"));
copy.setQueryItems(query);
QVERIFY(!copy.isEmpty());
}
示例7: setWebView
QQuickWebEngineView *GameUpQtPrivate::webView() const {
#else
QQuickWebView *GameUpQt::webView() const {
#endif
return m_webView;
}
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND
void GameUpQtPrivate::setWebView(QQuickWebEngineView *webView) {
#else
void GameUpQtPrivate::setWebView(QQuickWebView *webView) {
#endif
m_webView = webView;
}
Gamer *GameUpQtPrivate::getGamer() {
return &m_gamer;
}
QString GameUpQtPrivate::getLeaderboardID() const {
return m_leaderboardID;
}
void GameUpQtPrivate::setLeaderboardID(const QString &leaderboardID) {
m_leaderboardID = leaderboardID;
}
Leaderboard *GameUpQtPrivate::getLeaderboard(const QString &id) {
return m_leaderboards[id];
}
bool GameUpQtPrivate::getAsyncMode() const {
return m_asyncMode;
}
void GameUpQtPrivate::setAsyncMode(bool asyncMode) {
m_asyncMode = asyncMode;
}
QNetworkReply::NetworkError GameUpQtPrivate::getLasterror() const {
return lasterror;
}
QString GameUpQtPrivate::getLastToken() const {
return m_lastToken;
}
QQmlListProperty<Leaderboard> GameUpQtPrivate::leaderboards() {
QList<Leaderboard*> l = m_leaderboards.values();
return QQmlListProperty<Leaderboard>(this, l);
}
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND
void GameUpQtPrivate::webViewLoadingProgress(QQuickWebEngineLoadRequest *loadRequest) {
qDebug() << "loadrequest" << loadRequest->url() << loadRequest->errorCode() << loadRequest->status();
QUrlQuery query = QUrlQuery(loadRequest->url());
if (query.hasQueryItem("token")) {
m_lastToken = query.queryItemValue("token");
}
if (!m_lastToken.isEmpty()
|| loadRequest->errorCode() != 0
|| loadRequest->status() == QQuickWebEngineView::LoadFailedStatus
|| query.isEmpty()) {
disconnect(m_webView, &QQuickWebEngineView::loadingChanged, this, &GameUpQtPrivate::webViewLoadingProgress);
if (!m_asyncMode && loop.isRunning())
loop.quit();
emit reqComplete(GameUpQt::Login);
}
}