当前位置: 首页>>代码示例>>C++>>正文


C++ QWebEngineView类代码示例

本文整理汇总了C++中QWebEngineView的典型用法代码示例。如果您正苦于以下问题:C++ QWebEngineView类的具体用法?C++ QWebEngineView怎么用?C++ QWebEngineView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QWebEngineView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
//.........这里部分代码省略.........
开发者ID:gustavosbarreto,项目名称:electric-webview,代码行数:101,代码来源:commandhandler.cpp

示例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();
}
开发者ID:NCCA,项目名称:IntroToQt,代码行数:30,代码来源:MainWindow.cpp

示例3: QWebEngineView

void QRestClient::displayHtml(QByteArray html)
{
    QWebEngineView *view = new QWebEngineView();
    view->setAttribute(Qt::WA_DeleteOnClose);
    view->setHtml(html);
    view->show();
}
开发者ID:audifaxdev,项目名称:QRestClient,代码行数:7,代码来源:qrestclient.cpp

示例4: noteView

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);
}
开发者ID:FyhSky,项目名称:WizQTClient,代码行数:31,代码来源:titlebar.cpp

示例5: 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();
}
开发者ID:carlonluca,项目名称:pi,代码行数:32,代码来源:main.cpp

示例6: 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();
}
开发者ID:adam-zhang,项目名称:qt5_test,代码行数:8,代码来源:appMain.cpp

示例7: Q_D

QWebEnginePage* QWebEngineView::page() const
{
    Q_D(const QWebEngineView);
    if (!d->page) {
        QWebEngineView *that = const_cast<QWebEngineView*>(this);
        that->setPage(new QWebEnginePage(that));
    }
    return d->page;
}
开发者ID:elProxy,项目名称:qt-labs-qtwebengine,代码行数:9,代码来源:qwebengineview.cpp

示例8: Q_D

QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type)
{
    Q_D(QWebEnginePage);
    if (d->view) {
        QWebEngineView *newView = d->view->createWindow(type);
        if (newView)
            return newView->page();
    }
    return 0;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:10,代码来源:qwebenginepage.cpp

示例9: QWebEngineView

QWebEngineView *VUtils::getWebEngineView(QWidget *p_parent)
{
    QWebEngineView *viewer = new QWebEngineView(p_parent);
    VPreviewPage *page = new VPreviewPage(viewer);
    page->setBackgroundColor(Qt::transparent);
    viewer->setPage(page);
    viewer->setZoomFactor(g_config->getWebZoomFactor());

    return viewer;
}
开发者ID:liunianbanbo,项目名称:vnote,代码行数:10,代码来源:vutils.cpp

示例10: 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);
}
开发者ID:fuzzball81,项目名称:quassel,代码行数:28,代码来源:webpreviewitem.cpp

示例11: noteView

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);
    QUrl url = QUrl::fromLocalFile(strFileName);
    comments->setHtml(strHtml, url);
}
开发者ID:nil84,项目名称:WizQTClient,代码行数:15,代码来源:titlebar.cpp

示例12: show

void PublisherPage::show()
{
    QWebEngineView *view = new QWebEngineView;
    QDir dir;
    QString cwd = dir.currentPath();
    QString html = "qrc:///vpub/index.html";
    QString fpath = "/src/qt/res/vpub/index.html";
    QString res = cwd + fpath;
    QFile file(res);
    // QFile file("file:////res/pbt/index.html");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        html = QString("<html><body><p>Cannot read file in ") + res + QString("</p></body></html>");
    } else {
        html = QTextStream(&file).readAll();
    };
    view->setHtml(html, QUrl());
    view->show();
}
开发者ID:gjhiggins,项目名称:vcoincore,代码行数:18,代码来源:publisherpage.cpp

示例13: SetupWebView

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;
}
开发者ID:Roxee,项目名称:qt-roxeemegaup,代码行数:18,代码来源:main.cpp

示例14: main

int main(int argc, char *argv[])
{
    TaskConfig agent_cfg, config;
    if (!parseArgs(argc, argv, config, agent_cfg))
        return 1;
    agent_cfg.set("Measure.AutoSaveReport", "true");
    std::ofstream log_file;
    if (config.value("logfile") != "-") {
        log_file.open(config.value("logfile"));
        Logger::setLogFile(log_file);
    }

    config.set("listen_pw", MeasurementAgent::createHashKey(12));
    config.set("listen", "0");
    config.set("listen_addr", "127.0.0.1");
    config.set("browser",  "2");
    agent_cfg.set("config_file", config.value("config_file"));

    WebsocketBridge *bridge = new WebsocketBridge(nullptr, config);
    std::thread agent_thread(runAgent, bridge, agent_cfg);

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QWebEngineView view;
    view.resize(700, 950);
    view.show();

    // Wait for a few seconds for the agent to start listening on a port
    for (unsigned int i = 0; bridge->url().empty() && i < 400; ++i)
        std::this_thread::sleep_for(std::chrono::milliseconds(1+i/10));

    int ret;
    if (bridge->url().empty()) {
        std::cerr << "cannot start measurement engine";
        ret = 1;
    } else {
        view.setUrl(QUrl(bridge->url().c_str()));
        ret = app.exec();
    }

    bridge->die();
    agent_thread.join();
    return ret;
}
开发者ID:dotse,项目名称:bbk,代码行数:44,代码来源:main.cpp

示例15: main

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setQuitOnLastWindowClosed(false);
    app.setApplicationName("electric-webview");
    app.setApplicationVersion("1.0");

    QCommandLineParser cmdParser;
    cmdParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions);
    cmdParser.setApplicationDescription("Electric WebView is a scriptable WebView for developers.");
    cmdParser.addHelpOption();
    cmdParser.addVersionOption();
    cmdParser.addOption(QCommandLineOption(QStringList() << "t" << "transport", "Command Transport Layer to use.", "tcp|unixsocket|websocket"));
    cmdParser.addOption(QCommandLineOption(QStringList() << "r" << "reverse", "Enable reverse mode. The ID is used to identify your session in the server.", "ID"));
    cmdParser.addOption(QCommandLineOption(QStringList() << "s" << "script", "Script to run.", "path"));
    cmdParser.process(app);

    if (cmdParser.value("transport").isEmpty()) {
        qDebug().noquote() << "You must provide a command transport layer";
        return -1;
    }

    CommandServer *commandServer = new CommandServer();
    commandServer->setTransport(cmdParser.value("transport"));
    commandServer->setReverse(cmdParser.isSet("reverse"));
    commandServer->setReverseId(cmdParser.value("reverse"));
    commandServer->initialize();

    QWebEngineView *webView = new QWebEngineView;
    webView->setPage(new WebPage);

    ElectricWebView::instance()->setWebView(webView);

    ElectricWebView::instance()->initialize();

    QObject::connect(commandServer, &CommandServer::newCommand, ElectricWebView::instance()->commandHandler(), &CommandHandler::processCommand);

    if (cmdParser.isSet("script"))
        ElectricWebView::instance()->runScript(cmdParser.value("transport"), cmdParser.value("script"));

    return app.exec();
}
开发者ID:gustavosbarreto,项目名称:electric-webview,代码行数:42,代码来源:main.cpp


注:本文中的QWebEngineView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。