本文整理汇总了C++中QWebEngineView::load方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebEngineView::load方法的具体用法?C++ QWebEngineView::load怎么用?C++ QWebEngineView::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebEngineView
的用法示例。
在下文中一共展示了QWebEngineView::load方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processCommand
void CommandHandler::processCommand(const Command &command) const
{
QWebEngineView *webView = ElectricWebView::instance()->webView();
if (command.name() == "load") {
if (command.arguments().isEmpty())
webView->load(QUrl("about:blank"));
else
webView->load(QUrl(command.arguments().first()));
} else if (command.name() == "stop") {
webView->stop();
} else if (command.name() == "reload") {
webView->reload();
} else if (command.name() == "back") {
webView->back();
} else if (command.name() == "forward") {
webView->forward();
} else if (command.name() == "open") {
QString mode = command.arguments().value(0);
if (mode == "maximized") {
webView->showMaximized();
} else if (mode == "fullscreen") {
webView->setGeometry(qApp->desktop()->screenGeometry());
webView->showFullScreen();
}
} else if (command.name() == "close") {
webView->close();
} else if (command.name() == "current_url") {
command.sendResponse(webView->url().toString().toLocal8Bit());
} else if (command.name() == "set_html") {
QString type = command.arguments().value(0);
QString value = command.arguments().mid(1, -1).join(' ');
if (type == "string") {
webView->page()->setHtml(value.toLocal8Bit());
} else if (type == "file") {
QFile file(value);
file.open(QFile::ReadOnly);
webView->page()->setHtml(file.readAll());
}
} else if (command.name() == "get_html") {
QString format = command.arguments().value(0);
QEventLoop loop;
if (format == "html") {
webView->page()->toHtml([&command, &loop](const QString &html) {
if (!command.client().isNull()) {
command.sendResponse(QUrl::toPercentEncoding(html));
if (command.isGetter())
command.client()->close();
}
loop.quit();
});
} else if (format == "text") {
webView->page()->toPlainText([&command, &loop](const QString &text) {
if (!command.client().isNull()) {
command.sendResponse(QUrl::toPercentEncoding(text));
if (command.isGetter())
command.client()->close();
}
loop.quit();
});
} else {
return;
}
loop.exec();
} else if (command.name() == "current_title") {
command.sendResponse(webView->title().toLocal8Bit());
} else if (command.name() == "screenshot") {
processScreenshotCommand(command);
} else if (command.name() == "subscribe") {
QString eventName = command.arguments().value(0);
QStringList events = QStringList()
<< "title_changed"
<< "url_changed"
<< "load_started"
<< "load_finished"
<< "user_activity"
<< "info_message_raised"
<< "warning_message_raised"
<< "error_message_raised"
<< "feature_permission_requested";
if (events.contains(eventName)) {
Event event(command);
event.setName(eventName);
ElectricWebView::instance()->eventManager()->subscribe(event);
}
} else if (command.name() == "exec_js") {
processJavaScriptCommand(command);
} else if (command.name() == "inject_js") {
QMap<QString, QWebEngineScript::ScriptWorldId> worlds;
worlds["main"] = QWebEngineScript::MainWorld;
//.........这里部分代码省略.........
示例2: main
int main(int argc, char *argv[])
{
// make an instance of the QApplication
QApplication a(argc, argv);
// Create a new MainWindow
QMainWindow w;
QToolBar *toolbar= new QToolBar();
QPushButton *back= new QPushButton("back");
QPushButton *fwd= new QPushButton("fwd");
toolbar->addWidget(back);
toolbar->addWidget(fwd);
w.addToolBar(toolbar);
w.addToolBar(toolbar);
QWebEngineView *page = new QWebEngineView();
page->load(QUrl("http://www.google.co.uk"));
QObject::connect(back,SIGNAL(clicked()),page,SLOT(back()));
QObject::connect(fwd,SIGNAL(clicked()),page,SLOT(forward()));
w.setCentralWidget(page);
w.resize(1024,720);
// show it
w.show();
// hand control over to Qt framework
return a.exec();
}
示例3: main
/*------------------------------------------------------------------------------
| main
+-----------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
QApplication a(argc, argv);
QStringList args = a.arguments();
const bool opengl = !args.contains("--no-opengl");
args.removeAll("--no-opengl");
if (opengl) {
qDebug("QML QtWebEngine...");
QQuickView* view = new QQuickView;
view->setSource(QUrl("qrc:/poc_main.qml"));
view->showFullScreen();
QObject* o = view->rootObject()->findChild<QObject*>("webEngineView");
o->setProperty("url", args.at(1));
}
else {
qDebug("Widget QtWebEngine...");
QWebEngineView* view = new QWebEngineView;
view->load(QUrl(args.at(1)));
view->show();
}
return a.exec();
}
示例4: onTokenAcquired
void TitleBar::onTokenAcquired(const QString& strToken)
{
WizService::Token::instance()->disconnect(this);
#ifdef USEWEBENGINE
QWebEngineView* comments = noteView()->commentView();
#else
QWebView* comments = noteView()->commentView();
#endif
if (strToken.isEmpty()) {
comments->hide();
return;
}
QString strKbGUID = noteView()->note().strKbGUID;
QString strGUID = noteView()->note().strGUID;
m_commentsUrl = WizService::ApiEntry::commentUrl(strToken, strKbGUID, strGUID);
if (comments->isVisible()) {
// comments->load(QUrl());
comments->load(m_commentsUrl);
}
QUrl kUrl(WizService::ApiEntry::kUrlFromGuid(strToken, strKbGUID));
QString strCountUrl = WizService::ApiEntry::commentCountUrl(kUrl.host(), strToken, strKbGUID, strGUID);
WizService::AsyncApi* api = new WizService::AsyncApi(this);
connect(api, SIGNAL(getCommentsCountFinished(int)), SLOT(onGetCommentsCountFinished(int)));
api->getCommentsCount(strCountUrl);
}
示例5: onCommentsButtonClicked
void TitleBar::onCommentsButtonClicked()
{
#ifdef USEWEBENGINE
QWebEngineView* comments = noteView()->commentView();
#else
QWebView* comments = noteView()->commentView();
#endif
if (comments->isVisible()) {
comments->hide();
return;
}
if (isNetworkAccessible()) {
if (!m_commentsUrl.isEmpty()) {
comments->load(m_commentsUrl);
QSplitter* splitter = qobject_cast<QSplitter*>(comments->parentWidget());
Q_ASSERT(splitter);
QList<int> li = splitter->sizes();
Q_ASSERT(li.size() == 2);
QList<int> lin;
lin.push_back(li.value(0) - COMMENT_FRAME_WIDTH);
lin.push_back(li.value(1) + COMMENT_FRAME_WIDTH);
splitter->setSizes(lin);
comments->show();
} else {
loadErrorPage();
comments->show();
}
} else {
m_commentsBtn->setEnabled(false);
}
}
示例6: QGraphicsItem
WebPreviewItem::WebPreviewItem(const QUrl& url)
: QGraphicsItem(nullptr)
, // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines
_boundingRect(0, 0, 400, 300)
{
qreal frameWidth = 5;
QGraphicsProxyWidget* proxyItem = new QGraphicsProxyWidget(this);
# ifdef HAVE_WEBENGINE
QWebEngineView* webView = new CustomWebView(proxyItem);
webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
# elif defined HAVE_WEBKIT
QWebView* webView = new QWebView;
webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
# endif
webView->load(url);
webView->setDisabled(true);
webView->resize(1000, 750);
proxyItem->setWidget(webView);
proxyItem->setAcceptHoverEvents(false);
qreal xScale = (_boundingRect.width() - 2 * frameWidth) / webView->width();
qreal yScale = (_boundingRect.height() - 2 * frameWidth) / webView->height();
proxyItem->setTransform(QTransform::fromScale(xScale, yScale), true);
proxyItem->setPos(frameWidth, frameWidth);
setZValue(30);
}
示例7: main
int main(int argc, char** argv)
{
QApplication a(argc, argv);
QWebEngineView v;
v.load(QUrl("http://www.baidu.com"));
v.show();
return a.exec();
}
示例8: loadErrorPage
void TitleBar::loadErrorPage()
{
#ifdef USEWEBENGINE
QWebEngineView* comments = noteView()->commentView();
#else
noteView()->commentWidget()->hideLocalProgress();
QWebView* comments = noteView()->commentView();
comments->setVisible(true);
#endif
QString strFileName = Utils::PathResolve::resourcesPath() + "files/errorpage/load_fail_comments.html";
QString strHtml;
::WizLoadUnicodeTextFromFile(strFileName, strHtml);
// clear old url
comments->load(QUrl());
QUrl url = QUrl::fromLocalFile(strFileName);
comments->load(url);
}
示例9: jsFileInfo
QWebChannel * SetupWebView()
{
QFileInfo jsFileInfo(QDir::currentPath() + QString::fromLatin1("/qwebchannel.js"));
if (!jsFileInfo.exists())
QFile::copy(QString::fromLatin1(":/qtwebchannel/qwebchannel.js"), jsFileInfo.absoluteFilePath());
QtWebEngine::initialize();
QWebEngineView * view = new QWebEngineView();
QWebChannel * channel = new QWebChannel(view->page());
view->page()->setWebChannel(channel);
view->load(QUrl(QString::fromLatin1("qrc:/demo.html")));
view->show();
return channel;
}
示例10: main
int main(int argc, char *argv[]) {
// инициализация окна
QApplication a(argc, argv);
QWebEngineView *view = new QWebEngineView();
// размеры окна
int WIDTH = 1024;
int HEIGHT = 520;
// размеры Desktop
int screenWidth;
int screenHeight;
// centered
int x, y;
// расчет значений Desktop
QDesktopWidget *desktop = QApplication::desktop();
screenWidth = desktop->width();
screenHeight = desktop->height();
// новые значения
x = (screenWidth - WIDTH) / 2;
y = (screenHeight - HEIGHT) / 2;
// центрируем window
view->resize(WIDTH, HEIGHT);
view->move(x, y);
// title window
view->setWindowTitle("Игра жизнь");
// отключаем ненужные Qt события
view->setContextMenuPolicy(Qt::CustomContextMenu);
// подгружаем визуализацию
view->load(QUrl("qrc:live.html"));
view->show();
return a.exec();
}
示例11: loginInteractive
void LoginManager::loginInteractive()
{
QWebEngineView* webView = new QWebEngineView;
webView->setWindowModality(Qt::ApplicationModal);
webView->setAttribute(Qt::WA_DeleteOnClose);
QWebEnginePage* page = webView->page();
QWebEngineProfile* profile = page->profile();
// TODO: logout in editor does not log out in web view
profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
profile->setRequestInterceptor(new ApiWebEngineRequestInterceptor(profile));
//workaround for the crashes sometimes happend in Chromium on macOS with Qt 5.12
connect(webView, &QWebEngineView::renderProcessTerminated, this, [profile, webView](QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)
{
qDebug() << "Login page loading terminated" << terminationStatus << " " << exitCode;
profile->clearHttpCache();
webView->show();
});
connect(page, &QWebEnginePage::loadFinished, this, [this, page, webView](bool ok) {
if (!ok)
return;
constexpr QUrl::FormattingOptions cmpOpt = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
if (!page->url().matches(ApiInfo::loginSuccessUrl, cmpOpt))
return;
page->runJavaScript("JSON.stringify(muGetAuthInfo())", [this, page, webView](const QVariant& v) {
onLoginReply(nullptr, HTTP_OK, QJsonDocument::fromJson(v.toString().toUtf8()).object());
// We have retrieved an access token, do not remain logged
// in with web view profile.
page->profile()->cookieStore()->deleteAllCookies();
webView->close();
});
});
webView->load(ApiInfo::loginUrl);
webView->show();
}
示例12: openPDFWindow
void MainWindow::openPDFWindow(QString url){
QWebEngineView * pdfView;
if(!pdfViewList.contains(url)){
pdfView = new QWebEngineView(0);
QUrl theurl = QUrl(url);
pdfView->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
pdfView->load( theurl );
pdfView->show();
pdfViewList.insert(url, pdfView);
pdfView->setAttribute(Qt::WA_DeleteOnClose);
pdfView->showNormal();
int frameHeight = pdfView->frameGeometry().height()-pdfView->geometry().height();
pdfView->move( (screenRect.width() - 640)/2, screenRect.y() );
pdfView->resize( 640, screenRect.height()-frameHeight );
connect(pdfView, SIGNAL(destroyed(QObject*)), this, SLOT(onPDFViewClose(QObject*)) );
//pdfView->settings()->enablePersistentStorage(QDir::tempPath());
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
}else{
示例13: show
void GUIHelpViewer::show()
{
QWebEngineView *view = new QWebEngineView();
view->load(QUrl(this->currentUrl));
view->show();
}
示例14: QWebEngineView
// ============= QWebEngine ====================
extern "C" MSVC_API void qteQWebEng_init() {
QWebEngineView *view = new QWebEngineView(NULL);
view->load(QUrl("http://qt-project.org/"));
view->show();
}