本文整理汇总了C++中QWebFrame::setHtml方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebFrame::setHtml方法的具体用法?C++ QWebFrame::setHtml怎么用?C++ QWebFrame::setHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebFrame
的用法示例。
在下文中一共展示了QWebFrame::setHtml方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setHtml
void QWebFrameProto::setHtml(const QString & html, const QUrl & baseUrl)
{
scriptDeprecated("QWebFrame will not be available in future versions");
QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject());
if (item)
item->setHtml(html, baseUrl);
}
示例2: handleUnsupportedContent
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::ProtocolUnknownError) {
QSettings settings;
settings.beginGroup(QLatin1String("WebView"));
QStringList externalSchemes;
externalSchemes = settings.value(QLatin1String("externalSchemes")).toStringList();
if (externalSchemes.contains(reply->url().scheme()))
QDesktopServices::openUrl(reply->url());
return;
}
if (reply->error() == QNetworkReply::NoError) {
if (reply->header(QNetworkRequest::ContentTypeHeader).isValid())
BrowserApplication::downloadManager()->handleUnsupportedContent(reply);
return;
}
QFile file(QLatin1String(":/notfound.html"));
bool isOpened = file.open(QIODevice::ReadOnly);
Q_ASSERT(isOpened);
QString title = tr("Error loading page: %1").arg(reply->url().toString());
QString html = QString(QLatin1String(file.readAll()))
.arg(title)
.arg(reply->errorString())
.arg(reply->url().toString());
QBuffer imageBuffer;
imageBuffer.open(QBuffer::ReadWrite);
QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view());
QPixmap pixmap = icon.pixmap(QSize(32, 32));
if (pixmap.save(&imageBuffer, "PNG")) {
html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
QString(QLatin1String(imageBuffer.buffer().toBase64())));
}
QList<QWebFrame*> frames;
frames.append(mainFrame());
while (!frames.isEmpty()) {
QWebFrame *frame = frames.takeFirst();
if (frame->url() == reply->url()) {
frame->setHtml(html, reply->url());
return;
}
QList<QWebFrame *> children = frame->childFrames();
foreach (QWebFrame *frame, children)
frames.append(frame);
}
if (m_loadingUrl == reply->url()) {
mainFrame()->setHtml(html, reply->url());
}
}
示例3: handleUnsupportedContent
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
QString errorString = reply->errorString();
if (m_loadingUrl != reply->url()) {
// sub resource of this page
qWarning() << "Resource" << reply->url().toEncoded() << "has unknown Content-Type, will be ignored.";
reply->deleteLater();
return;
}
if (reply->error() == QNetworkReply::NoError && !reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
errorString = "Unknown Content-Type";
}
QFile file(QLatin1String(":/notfound.html"));
bool isOpened = file.open(QIODevice::ReadOnly);
Q_ASSERT(isOpened);
Q_UNUSED(isOpened)
QString title = tr("Error loading page: %1").arg(reply->url().toString());
QString html = QString(QLatin1String(file.readAll()))
.arg(title)
.arg(errorString)
.arg(reply->url().toString());
QBuffer imageBuffer;
imageBuffer.open(QBuffer::ReadWrite);
QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view());
QPixmap pixmap = icon.pixmap(QSize(32,32));
if (pixmap.save(&imageBuffer, "PNG")) {
html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
QString(QLatin1String(imageBuffer.buffer().toBase64())));
}
QList<QWebFrame*> frames;
frames.append(mainFrame());
while (!frames.isEmpty()) {
QWebFrame *frame = frames.takeFirst();
if (frame->url() == reply->url()) {
frame->setHtml(html, reply->url());
return;
}
QList<QWebFrame *> children = frame->childFrames();
foreach(QWebFrame *frame, children)
frames.append(frame);
}
if (m_loadingUrl == reply->url()) {
mainFrame()->setHtml(html, reply->url());
}
}
示例4: getTitle
QString ForumProbe::getTitle(QString &html) {
QString title;
#ifndef NO_WEBKITWIDGETS
QWebPage *page = new QWebPage();
QWebFrame *frame = page->mainFrame();
frame->setHtml(html);
title = frame->title();
page->deleteLater();
#else
int titleBegin = html.indexOf("<title>");
if(titleBegin > 0) {
int titleEnd = html.indexOf("</", titleBegin);
title = html.mid(titleBegin + 7, titleEnd - titleBegin - 7);
}
#endif
return title;
}
示例5: onHandleUnsupportedContent
void HelpPage::onHandleUnsupportedContent(QNetworkReply *reply)
{
// sub resource of this page
if (m_loadingUrl != reply->url()) {
qWarning() << "Resource" << reply->url().toEncoded() << "has unknown Content-Type, will be ignored.";
reply->deleteLater();
return;
}
// set a default error string we are going to display
QString errorString = HelpViewer::tr("Unknown or unsupported Content!");
if (reply->error() == QNetworkReply::NoError) {
// try to open the url using using the desktop service
if (QDesktopServices::openUrl(reply->url())) {
reply->deleteLater();
return;
}
// seems we failed, now we show the error page inside creator
} else {
errorString = reply->errorString();
}
// setup html
const QString html = QString::fromLatin1(g_htmlPage).arg(g_percent1, errorString,
HelpViewer::tr("Error loading: %1").arg(reply->url().toString()), g_percent4, g_percent5, g_percent6,
g_percent7);
// update the current layout
QList<QWebFrame*> frames;
frames.append(mainFrame());
while (!frames.isEmpty()) {
QWebFrame *frame = frames.takeFirst();
if (frame->url() == reply->url()) {
frame->setHtml(html, reply->url());
return;
}
QList<QWebFrame *> children = frame->childFrames();
foreach (QWebFrame *frame, children)
frames.append(frame);
}
if (m_loadingUrl == reply->url())
mainFrame()->setHtml(html, reply->url());
}
示例6: applyEncoding
void WebView::applyEncoding()
{
if (m_encoding_in_progress)
return;
if (webPage() && webPage()->mainWindow())
{
QString enc = webPage()->mainWindow()->m_currentEncoding;
if (enc.isEmpty())
return;
if (enc == m_current_encoding && m_current_encoding_url == url() )
return;
QWebPage *page = webPage();
if (!page)
return;
QWebFrame *mainframe = page->mainFrame();
if (!mainframe)
return;
QString html = mainframe->toHtml();
QTextCodec *codec = QTextCodec::codecForName( enc.toAscii() );
if (!codec)
return;
QTextDecoder *decoder = codec->makeDecoder();
if (!decoder)
return;
m_encoding_in_progress = true;
m_current_encoding = enc;
m_current_encoding_url = url();
QString output = decoder->toUnicode(html.toAscii());
mainframe->setHtml(output, mainframe->url());
QList<QWebFrame *> children = mainframe->childFrames();
foreach(QWebFrame *frame, children)
{
html = frame->toHtml();
output = decoder->toUnicode(html.toAscii());
frame->setHtml(output, frame->url());
}
示例7: reusePage
void tst_QWebView::reusePage()
{
if (!QDir(TESTS_SOURCE_DIR).exists())
QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll);
QDir::setCurrent(TESTS_SOURCE_DIR);
QFETCH(QString, html);
QWebView* view1 = new QWebView;
QPointer<QWebPage> page = new QWebPage;
view1->setPage(page);
page->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
QWebFrame* mainFrame = page->mainFrame();
mainFrame->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR));
if (html.contains("</embed>")) {
// some reasonable time for the PluginStream to feed test.swf to flash and start painting
waitForSignal(view1, SIGNAL(loadFinished(bool)), 2000);
}
示例8: render
void downloader::render(QString rawHtml)
{
currencyLoaded.clear();
rateLoaded.clear();
QWebFrame *mainFrame = webPage.mainFrame();
mainFrame->setHtml(rawHtml);
QWebElement documentElement = mainFrame->documentElement();
QWebElementCollection elements = documentElement.findAll("#content > div:nth-child(1) > div > div.col2.pull-right.module.bottomMargin > div.moduleContent > table:nth-child(4) > tbody > tr");
int i = 0;
foreach (QWebElement element, elements)
{
currency.push_back(element.findFirst("td:nth-child(1)").toInnerXml());
rate.push_back(element.findFirst("td:nth-child(3) > a").toInnerXml());
// qDebug()<< currency[i+(elements.count()*downloadCount)]+"\t\t"+rate[i+(elements.count()*downloadCount)]+"\n";
currencyLoaded.push_back(currency[i+(elements.count()*downloadCount)]);
rateLoaded.push_back(rate[i+(elements.count()*downloadCount)]);
i++;
}
示例9: handleUnsupportedContent
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
if (reply->header(QNetworkRequest::ContentTypeHeader).isValid())
qDebug() << "download it";
new OpDownloader(reply);
return;
}
if (reply->error() == QNetworkReply::ProtocolUnknownError) {
// we currently don't support protocol other than http(s):// and file://
// return;
}
//display notfound
if (reply->url().isEmpty())
return;
QFile file(QLatin1String(":/notfound.html"));
bool isOpened = file.open(QIODevice::ReadOnly);
Q_ASSERT(isOpened);
QString title = ("HTTP 404 Not Found");
QString html = QString(QLatin1String(file.readAll()));
QList<QWebFrame*> frames;
frames.append(mainFrame());
while (!frames.isEmpty()) {
QWebFrame *frame = frames.takeFirst();
if (frame->url() == reply->url()) {
frame->setHtml(html, reply->url());
return;
}
QList<QWebFrame *> children = frame->childFrames();
foreach (QWebFrame *frame, children)
frames.append(frame);
}
if (m_loadingUrl == reply->url()) {
mainFrame()->setHtml(html, reply->url());
}
}
示例10: addMessage
void
MainWindow::channelChanged()
{
QListWidgetItem* item = this->ui->listview_channels->currentItem();
if (item) {
this->currentChannel = item->text();
this->ui->wChannel->setText(item->text());
this->ui->wInput->setEnabled(true);
this->ui->wSend->setEnabled(true);
auto messages = read.getMessages(item->text());
QString html;
QWebFrame* frame = this->ui->baseChatWindow->page()->mainFrame();
frame->setHtml("");
for (int i = 0; i < messages->count(); ++i) {
auto message = messages->at(i);
addMessage(message);
}
this->scrollValue = 0;
this->autoScroll = true;
}
}
示例11: handleUnsupportedContent
void WBWebPage::handleUnsupportedContent(QNetworkReply *reply)
{
if(reply->url().scheme() == "mailto")
{
bool result = QDesktopServices::openUrl(reply->url());
if (result)
return;
}
QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
bool isPDF = (contentType == "application/pdf");
// Delete this big "if (isPDF)" block to get the pdf directly inside the browser
if (isPDF)
{
QMessageBox messageBox(mainWindow());
messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Sankore document?"));
messageBox.addButton(tr("Download"), QMessageBox::AcceptRole);
QAbstractButton *addButton =
messageBox.addButton(tr("Add to Current Document"), QMessageBox::AcceptRole);
messageBox.exec();
if (messageBox.clickedButton() == addButton)
{
UBApplication::applicationController->showBoard();
UBApplication::boardController->downloadURL(reply->request().url());
return;
}
else
{
isPDF = false;
}
}
if (!isPDF && reply->error() == QNetworkReply::NoError)
{
if(contentType == "application/widget")
WBBrowserWindow::downloadManager()->handleUnsupportedContent(reply,false, UBSettings::settings()->uniboardGipLibraryDirectory());
else
WBBrowserWindow::downloadManager()->handleUnsupportedContent(reply);
return;
}
QFile file;
file.setFileName(isPDF ? QLatin1String(":/webbrowser/object-wrapper.html") : QLatin1String(":/webbrowser/notfound.html"));
bool isOpened = file.open(QIODevice::ReadOnly);
Q_ASSERT(isOpened);
QString html;
if (isPDF)
{
html = QString(QLatin1String(file.readAll()))
.arg(tr("PDF"))
.arg("application/x-ub-pdf")
.arg(reply->url().toString());
}
else
{
QString title = tr("Error loading page: %1").arg(reply->url().toString());
html = QString(QLatin1String(file.readAll()))
.arg(title)
.arg(reply->errorString())
.arg(reply->url().toString());
}
QList<QWebFrame*> frames;
frames.append(mainFrame());
while (!frames.isEmpty())
{
QWebFrame *frame = frames.takeFirst();
if (frame->url() == reply->url())
{
frame->setHtml(html, reply->url());
return;
}
QList<QWebFrame *> children = frame->childFrames();
foreach(QWebFrame *frame, children)
frames.append(frame);
}
if (mLoadingUrl == reply->url())
{
mainFrame()->setHtml(html, reply->url());
}
}
示例12: networkFinished
void CadastreWrapper::networkFinished(QNetworkReply *reply)
{
if (m_pendingTiles.contains(reply)) {
QFile target(m_pendingTiles[reply]);
QByteArray ba = reply->readAll();
// white -> transparent
QImage img;
img.loadFromData(ba);
QImage img2 = img.convertToFormat(QImage::Format_ARGB32);
Q_ASSERT(img2.hasAlphaChannel());
int w=0;
for (int y=0; y<img2.height(); ++y) {
for (int x=0; x<img2.width(); ++x) {
QColor col = QColor(img2.pixel(x, y));
if (col == QColor(255, 255, 255)) {
col.setAlpha(0);
img2.setPixel(x, y, col.rgba());
++w;
}
}
}
//Full transparent
if (w == img2.height()*img2.width()) {
img2 = QImage(1, 1, QImage::Format_ARGB32);
img2.setPixel(0, 0, QColor(0, 0, 0, 0).rgba());
}
target.open(QIODevice::WriteOnly);
// target.write(reply->readAll());
img2.save(&target, "PNG");
target.close();
m_pendingTiles.remove(reply);
if (m_progress) {
m_progress->setValue(m_progress->value()+1);
if (m_progress->value() > 10) {
double ms = m_startTime.secsTo(QDateTime::currentDateTime());
double us = ms/m_progress->value();
int tot = us*(m_progress->maximum() - m_progress->value());
if (tot<3600)
m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/60)).arg(int(tot%60), 2, 10, QChar('0')));
else
m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4:%5").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/3600)).arg(int((tot%3600)/60), 2, 10, QChar('0')).arg(int(tot%60), 2, 10, QChar('0')));
} else
m_progress->setLabelText(tr("Downloaded: %1/%2").arg(m_progress->value()).arg(m_progress->maximum()));
}
} else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/accueil.do")) {
qDebug() << "Ok, I've got a cookie... I LOVE COOKIES.";
reply->readAll();
m_gotCookie = true;
} else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/rechercherPlan.do")) {
QString pageData = reply->readAll();
qDebug() << pageData;
QWebPage parsedPage(this);
QWebFrame *frame = parsedPage.mainFrame();
frame->setHtml(pageData);
QWebElement codeCommune = frame->findFirstElement("#codeCommune");
QMap<QString, QString> results;
if (!codeCommune.isNull()) {
// If there is a codeCommune object in the DOM, it means that the search was not successfull.
if (codeCommune.tagName().toLower() != "select") {
qDebug() << "Invalid page ???";
return;
}
QWebElementCollection options = codeCommune.findAll("option");
foreach (QWebElement option, options) {
if (!option.attribute("value").isEmpty())
results[option.attribute("value")] = option.toPlainText();
}
} else {