本文整理汇总了C++中QWebFrame::findAllElements方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebFrame::findAllElements方法的具体用法?C++ QWebFrame::findAllElements怎么用?C++ QWebFrame::findAllElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebFrame
的用法示例。
在下文中一共展示了QWebFrame::findAllElements方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseSearchProductPage
//void ArestShopPlugin::SinglePageFound()
//{
//#ifdef USE_WEBKIT
// QWebFrame * ptrFrame = getWebPage()->mainFrame();
// parseProductPage(m_stCompData);
// m_stCompData.strCompURL = ptrFrame->url().toString();
// emit priceSearchedFinished(m_stCompData);
// productFoundFinish();
//#endif
//};
void ArestShopPlugin::parseSearchProductPage(SearchResult & stResult,bool & bNextPage)
{
//run XML search page parse
bNextPage=false;
#ifdef USE_WEBKIT
QWebFrame * ptrFrame = getWebPage()->mainFrame();
//////////////////////////////////////////////////////////////////////////
QWebElementCollection tableProdRows = ptrFrame->findAllElements("table[class=pricelist]");
for(int iIndex=0;iIndex<tableProdRows.count();++iIndex)
{
QWebElement prodNameHeader = tableProdRows.at(iIndex).findFirst("td[class=nazwa]");
if (prodNameHeader.isNull())
continue;
QWebElement productLink = prodNameHeader.findFirst("a");
QUrl stProductURL = productLink.attribute("href");
//////////////////////////////////////////////////////////////////////////
QString strName = productLink.toPlainText();
stResult.insert(std::make_pair(strName,stProductURL));
}
//////////////////////////////////////////////////////////////////////////
QWebElement tablePageNavi = ptrFrame->findFirstElement("li[class=next]");
if (tablePageNavi.isNull())
{
bNextPage=false;
return;
}
bNextPage=true;
#endif
stResult.insert(Arest::mSearchResult.begin(),Arest::mSearchResult.end());
bNextPage=m_bLoadNextPage;
}
示例2: findAllElements
QWebElementCollection QWebFrameProto::findAllElements(const QString & selectorQuery) const
{
scriptDeprecated("QWebFrame will not be available in future versions");
QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject());
if (item)
return item->findAllElements(selectorQuery);
return QWebElementCollection();
}
示例3: isSingleProductPage
bool ArestShopPlugin::isSingleProductPage()
{
#ifdef USE_WEBKIT
QWebFrame * ptrFrame = getWebPage()->mainFrame();
QWebElementCollection productPage = ptrFrame->findAllElements("h1[class=nazwatowaru]");
if (productPage.count())
return true;
#endif
return false;
}
示例4: isNotFoundPage
bool ArestShopPlugin::isNotFoundPage()
{
#ifdef USE_WEBKIT
QWebFrame * ptrFrame = getWebPage()->mainFrame();
QWebElementCollection notFoundPage = ptrFrame->findAllElements("div[class=searchfailed]");
if (notFoundPage.count())
return true;
#endif
return false;
}
示例5: togliBlank
void MainWindow::togliBlank(bool ok) {
if (!ok) {
return;
}
QWebFrame* frame = ui->webView->page()->mainFrame();
if (frame!=NULL) {
QWebElementCollection collection = frame->findAllElements("a[target=_blank]");
foreach (QWebElement element, collection) {
element.setAttribute("target", "_self");
}
示例6: checkRss
void WebView::checkRss()
{
if (m_rssChecked) {
return;
}
m_rssChecked = true;
QWebFrame* frame = page()->mainFrame();
const QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]");
m_hasRss = links.count() != 0;
emit rssChanged(m_hasRss);
}
示例7: returnWord
void wordsImporter::returnWord(QString word, QByteArray translation)
{
saveCard(word, translation); // Но туточки нужно не просто сохранить слово, но и запузырить обратный поиск!
QWebFrame * frame = page.mainFrame();
frame->setContent (translation);
if (backTranslation)
{
QWebElementCollection transl = frame->findAllElements(".b-translate a");
foreach (QWebElement h, transl) {
qDebug() << "translate back" << h.toPlainText();
emit translateItBack(h.toPlainText());
}
}
示例8: QFrame
RSSDetectionWidget::RSSDetectionWidget(WebView* view, QWidget* parent)
: QFrame(parent, Qt::Popup)
, view_(view)
{
setAttribute(Qt::WA_DeleteOnClose);
setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
setLineWidth(1);
setMidLineWidth(2);
gridLayout_ = new QGridLayout(this);
gridLayout_->setMargin(5);
gridLayout_->setSpacing(5);
QWebFrame* frame = view_->page()->mainFrame();
QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]");
int cols = links.count() / 10 == 0 ? 1 : links.count() / 10;
int row = 0;
for (int i = 0; i < links.count(); i++) {
QWebElement element = links.at(i);
QString title = element.attribute("title");
const QUrl url = QUrl::fromEncoded(element.attribute("href").toUtf8());
if (url.isEmpty()) {
continue;
}
if (title.isEmpty()) {
title = tr("Untitled feed");
}
QPushButton* button = new QPushButton(this);
button->setStyleSheet("QPushButton {text-align:left; border: none; padding: 0px;}"
"QPushButton:hover {color: #1155CC;}");
button->setCursor(Qt::PointingHandCursor);
button->setText(title);
button->setToolTip(url.toString());
button->setProperty("rss-url", url);
button->setProperty("rss-title", title);
int pos = i % cols > 0 ? (i % cols) * 2 : 0;
gridLayout_->addWidget(button, row, pos);
connect(button, SIGNAL(clicked()), this, SLOT(addRss()));
if (i % cols == cols - 1) {
row++;
}
}
}
示例9: foreach
void
CutyCapt::saveSnapshot() {
QWebFrame *mainFrame = mPage->mainFrame();
// TODO: sometimes contents/viewport can have size 0x0
// in which case saving them will fail. This is likely
// the result of the method being called too early. So
// far I've been unable to find a workaround, except
// using --delay with some substantial wait time. I've
// tried to resize multiple time, make a fake render,
// check for other events... This is primarily a problem
// under my Ubuntu virtual machine.
mPage->setViewportSize( mainFrame->contentsSize() );
if (mPage->fixedWidth != 0 && mPage->fixedHeight != 0) {
mPage->setViewportSize(QSize(mPage->fixedWidth, mPage->fixedHeight));
}
if (this-mPage->mSelector.count() > 0) {
QWebElementCollection collection = mainFrame->findAllElements(this->mPage->mSelector);
QJsonObject obj;
QJsonArray elements;
foreach(QWebElement elem, collection) {
QJsonObject e;
e["id"] = elem.attribute("id");
if (this->mPage->mRetina) {
e["x"] = elem.geometry().x() * 2;
e["y"] = elem.geometry().y() * 2;
e["width"] = elem.geometry().width() * 2;
e["height"] = elem.geometry().height() * 2;
}else{
e["x"] = elem.geometry().x();
e["y"] = elem.geometry().y();
e["width"] = elem.geometry().width();
e["height"] = elem.geometry().height();
}
elements.append(e);
}
示例10: finishLoading
void RWebBrowser::finishLoading(bool)
{
// m_progress = 100;
// adjustTitle();
QWebFrame* frame = m_webView->page()->mainFrame();
if (frame!=NULL)
{
QWebElementCollection elements = frame->findAllElements("a");
foreach (QWebElement element, elements)
{
QStringList attributesList = element.attributeNames();
foreach (QString attributeName, attributesList)
{
if (attributeName != "href") break;
QRegExp rx(".*.mp1$|.*.mp2$|.*.mp3$|.*.mp4$|.*.mpg$|.*.mpa$|.*.wav$|.*.ogg$|.*.m3u$|.*.pls$|.*.xspf$");
rx.setCaseSensitivity(Qt::CaseInsensitive);
if (element.attribute(attributeName).contains(rx))
{
QUrl baseUrl(m_webView->url());
QUrl relativeUrl = QUrl::fromEncoded(element.attribute(attributeName).toUtf8(), QUrl::StrictMode);
QString streamName = baseUrl.resolved(relativeUrl).toString();
qDebug() << streamName;
//test button
QPushButton *testButton = new QPushButton(streamName);
m_buttonLayout->addWidget(testButton);
//
}
}
}
示例11: post
void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgoingData)
{
//Dont save in private browsing
if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
return;
}
m_lastOutgoingData = outgoingData;
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
if (!webPage) {
return;
}
WebView* webView = qobject_cast<WebView*>(webPage->view());
if (!webView) {
return;
}
v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101));
QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt();
if (type != QWebPage::NavigationTypeFormSubmitted) {
return;
}
QString usernameName;
QString usernameValue;
QString passwordName;
QString passwordValue;
QUrl siteUrl = webPage->url();
if (!isStoringEnabled(siteUrl)) {
return;
}
QWebElementCollection allForms; // All form elements on page
QWebElement foundForm; // Sent form element
QList<QWebFrame*> frames;
frames.append(webPage->mainFrame()); // Find all form elements
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
allForms.append(frame->findAllElements("form"));
frames += frame->childFrames();
}
foreach(const QWebElement & formElement, allForms) {
foreach(const QWebElement &inputElement, formElement.findAll("input[type=\"password\"]")) {
passwordName = inputElement.attribute("name");
passwordValue = getValueFromData(outgoingData, inputElement);
if (!passwordValue.isEmpty() && dataContains(outgoingData, passwordName)) {
foundForm = formElement;
break;
}
}
if (!foundForm.isNull()) {
break;
}
}
示例12: completePage
void AutoFillModel::completePage(WebPage* page)
{
if (!page) {
return;
}
QUrl pageUrl = page->url();
if (!isStored(pageUrl)) {
return;
}
QWebElementCollection inputs;
QList<QWebFrame*> frames;
frames.append(page->mainFrame());
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
inputs.append(frame->findAllElements("input"));
frames += frame->childFrames();
}
QString server = pageUrl.host();
if (server.isEmpty()) {
server = pageUrl.toString();
}
QSqlQuery query;
query.prepare("SELECT data FROM autofill WHERE server=?");
query.addBindValue(server);
query.exec();
query.next();
QByteArray data = query.value(0).toByteArray();
if (data.isEmpty()) {
return;
}
// Why not to use encodedQueryItems = QByteArrays ?
// Because we need to filter "+" characters that must be spaces
// (not real "+" characters "%2B")
QueryItems arguments = QUrl::fromEncoded("http://bla.com/?" + data).queryItems();
for (int i = 0; i < arguments.count(); i++) {
QString key = arguments.at(i).first;
QString value = arguments.at(i).second;
key.replace("+", " ");
value.replace("+", " ");
key = QUrl::fromEncoded(key.toUtf8()).toString();
value = QUrl::fromEncoded(value.toUtf8()).toString();
for (int i = 0; i < inputs.count(); i++) {
QWebElement element = inputs.at(i);
if (element.attribute("type") != "text" && element.attribute("type") != "password" && element.attribute("type") != "") {
continue;
}
if (key == element.attribute("name")) {
element.setAttribute("value", value);
}
}
}
}
示例13: QDialog
SiteInfo::SiteInfo(WebView* view, QWidget* parent)
: QDialog(parent)
, ui(new Ui::SiteInfo)
, m_certWidget(0)
, m_view(view)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
ui->listWidget->item(0)->setIcon(QIcon::fromTheme("document-properties", QIcon(":/icons/preferences/document-properties.png")));
ui->listWidget->item(1)->setIcon(QIcon::fromTheme("applications-graphics", QIcon(":/icons/preferences/applications-graphics.png")));
ui->listWidget->item(2)->setIcon(QIcon::fromTheme("text-x-sql", QIcon(":/icons/preferences/text-x-sql.png")));
ui->listWidget->item(3)->setIcon(QIcon::fromTheme("dialog-password", QIcon(":/icons/preferences/dialog-password.png")));
ui->listWidget->item(0)->setSelected(true);
WebPage* webPage = view->page();
QWebFrame* frame = view->page()->mainFrame();
QString title = view->title();
QSslCertificate cert = webPage->sslCertificate();
m_baseUrl = frame->baseUrl();
//GENERAL
ui->heading->setText(QString("<b>%1</b>:").arg(title));
ui->siteAddress->setText(view->url().toString());
ui->sizeLabel->setText(qz_fileSizeToString(webPage->totalBytes()));
QString encoding;
//Meta
QWebElementCollection meta = frame->findAllElements("meta");
for (int i = 0; i < meta.count(); i++) {
QWebElement element = meta.at(i);
QString content = element.attribute("content");
QString name = element.attribute("name");
if (name.isEmpty()) {
name = element.attribute("http-equiv");
}
if (!element.attribute("charset").isEmpty()) {
encoding = element.attribute("charset");
}
if (content.contains(QLatin1String("charset="))) {
encoding = content.mid(content.indexOf(QLatin1String("charset=")) + 8);
}
if (content.isEmpty() || name.isEmpty()) {
continue;
}
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeTags);
item->setText(0, name);
item->setText(1, content);
ui->treeTags->addTopLevelItem(item);
}
if (encoding.isEmpty()) {
encoding = mApp->webSettings()->defaultTextEncoding();
}
ui->encodingLabel->setText(encoding.toUpper());
//MEDIA
QWebElementCollection img = frame->findAllElements("img");
for (int i = 0; i < img.count(); i++) {
QWebElement element = img.at(i);
QString src = element.attribute("src");
QString alt = element.attribute("alt");
if (alt.isEmpty()) {
if (src.indexOf(QLatin1Char('/')) == -1) {
alt = src;
}
else {
int pos = src.lastIndexOf(QLatin1Char('/'));
alt = src.mid(pos);
alt.remove(QLatin1Char('/'));
}
}
if (src.isEmpty() || alt.isEmpty()) {
continue;
}
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeImages);
item->setText(0, alt);
item->setText(1, src);
ui->treeImages->addTopLevelItem(item);
}
//DATABASES
const QList<QWebDatabase> &databases = frame->securityOrigin().databases();
int counter = 0;
foreach(const QWebDatabase & b, databases) {
QListWidgetItem* item = new QListWidgetItem(ui->databaseList);
item->setText(b.displayName());
item->setData(Qt::UserRole + 10, counter);
++counter;
}