Code Monkey home page Code Monkey logo

qcefview's Introduction

QCefView

Introduction

QCefView is a Qt based QWidget which encapsulates CEF. With QCefView you can build your application UI in frontend developing way to boost your project. And what's more you can completely decouple the UI and business logic in your project. The most important thing is to be able to better use CEF in Qt.

Support platform

Platform Lastest Build Status OSR Production Ready NCW Production Ready
Windows-x86_64 Build on Windows ✔️ ✔️
macOS-x86_64 Build on macOS ✔️ ✔️
Linux-x86_64 Build on Linux ✔️
  • OSR = Offscreen Rendering Mode

  • NCW = Native Child Window Mode

Quick Start

Clone this project

git clone https://github.com/CefView/QCefView.git

The dependency to CefViewCore has been converted to CMake FetchContent, submodule is not needed anymore. Pleaser refer to: cmake/CefViewCoreConfig.cmake

Documentation

You can find the latest documentation here:

It can help you quickly understand how to use it.

Note For Debugging With Xcode

if you want to debug the project with Xcode, you need to take some action to make sure the demo project could load QCefView at correct location.

  1. Generate project with cmake
  2. Build demo project with xcode, do not run (actually you will encounter errors if you run directly)
  3. Go to the Build Phases for target QCefViewDemo and perform the actions below
    • remove all items under Target Dependencies
    • remove all items under Link Binary With Libraries
  4. Now you can debug demo project in Xcode without errors

if you re-generated the project, please remember to re-do the instructions above

About OSR mode

QCefView supports CEF offscreen rendering mode and this feature is enabled by default at runtime, to disable OSR mode you need to set the config item setWindowlessRenderingEnabled to false

  QCefConfig config;

// WindowlessRenderingEnabled is set to true by default, set to false to disable the OSR mode
 config.setWindowlessRenderingEnabled(false)

QCefView currently uses Qt Software Rasterizer as the backend paint engine for best compatibility, thus the rendering performance is not so good to be applied for all business scenarios. If you want to host WebGL games, video sites or some other Web Apps with high rendering performance, Non OSR mode (Native Child Window mode) is recommended.

Question

Why not OpenGL/DirectX/Metal?

QCefView was designed to be a common Qt widget for Desktop application, so the compatibility is the first important requirement. We can switch the backend engine from Software Rasterizer to OpenGL/DirectX/Metal but this will increase the complexity and decrease the compatibility of QCefView.

For example if we use OpenGL as the backend engine then all the applications with QCefView introduced will be switched to OpenGL backend automatically. I believe not all users want this to happen.

DirectX/Metal are platform dependent and they are not supported natively by Qt. If we provide QCefView with extra dependencies individually, this makes QCefView so different with other components in Qt Framework.

But if you must use OSR and the rendering performance is vital, you can try to switch the backend with whatever you want.

Contributing

This project welcomes contributions and suggestions. Make sure to align your code style with the configuration defined by .clang-format file

Making contributions is not a hard thing.

  • Solving an issue(maybe just answering a question raised in issues list or gitter)
  • Fixing/Issuing a bug
  • Improving the documents and even fixing a typo

are important contributions to QCefView If you would like to become one of QCefView's maintainers to contribute more (e.g. help merge PR, triage issues), please contact me by email(sheentianshen#gmail.com). I am glad to help you to set the right permission.

qcefview's People

Contributors

be-water-myfriend avatar edny1 avatar jackjackphp avatar l-super avatar le0zh avatar leashi avatar mogoweb avatar ogretransporter avatar tishion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qcefview's Issues

请问支持Linux么

请问支持Linux么,还有这个占用多大空间,qt自身的webengine占用空间太大了。

Mac OSX 编译

@tishion HI,能提供一下Mac OSX平台下的使用教程吗?XCode编译好QCefView.framework,QT项目编译正常通过,运行崩溃。

Delete cefview ,crash

void
QCefViewTest::onBtnNew()
{
QDir dir = QCoreApplication::applicationDirPath();
QString uri = QDir::toNativeSeparators(dir.filePath("QCefViewTestPage.html"));
cefview = new CustomCefView(uri, this);
// cefview = new CustomCefView("http://www.google.com/", this);
ui.cefContainer->layout()->addWidget(cefview);
}

void
QCefViewTest::onBtnDelete()
{
ui.cefContainer->layout()->removeWidget(cefview);
delete cefview;
cefview = nullptr;
}

crash after delete cefview

Cannot close application in some situations

Hi,
When I only open the main window, I can close it correctly. But if I open some popup window, such as a devtools, I try to close it, the popup windows can close, but the main window cannot close. I found in this situation, for the main_browser_, only execuate the 'DoClose()' function, not execuate 'OnBeforeClose()', in QCefViewBrowserHandler. It makes the application blocked at the lock.

您好,请问在编译时makefile报错怎么解决

您好,我在使用./generate-linux-proj.sh -b编译qcefview时,在最后报了这个错误,导致makefile无法正常执行。
1646704554(1)

collect2: error: ld returned 1 exit status
example/QCefViewTest/CMakeFiles/QCefViewTest.dir/build.make:170: recipe for target 'output/Debug/bin/QCefViewTest' failed
make[2]: *** [output/Debug/bin/QCefViewTest] Error 1
CMakeFiles/Makefile2:304: recipe for target 'example/QCefViewTest/CMakeFiles/QCefViewTest.dir/all' failed
make[1]: *** [example/QCefViewTest/CMakeFiles/QCefViewTest.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

mCefView->executeJavascript(QCefView::MainFrameID, callbackString, "") Crash

void WBWebViewComponent::runJavaScript(const QString &callbackString)
{
bool ok = mCefView->executeJavascript(QCefView::MainFrameID, callbackString, "");
qDebug()<<FUNCTION<<ok;
}
is Crash

fix: this Crash
修改代码如下,可解决Carsh
bool QCefViewPrivate::executeJavascript(int64_t frameId, const QString& code, const QString& url)
{
if (pCefBrowser_) {
auto frame = frameId == 0 ? pCefBrowser_->GetMainFrame() : pCefBrowser_->GetFrame(frameId);
//CefRefPtr frame = pCefBrowser_->GetFrame(frameId);
if (frame) {
CefString c;
c.FromString(code.toStdString());

  CefString u;
  if (url.isEmpty()) {
    u = frame->GetURL();
  } else {
    u.FromString(url.toStdString());
  }
  frame->ExecuteJavaScript(c, u, 0);

  return true;
}

}

return false;
}

qml usage

Hi,
Is there a way to use it as a qml component ?
Regards,
Steph

在Linux下窗口好像有问题

在Ubuntu20.04下, 将创建浏览器的代码,移到按钮点击的时候创建, 貌似窗口刷新不正常。还不确定问题在哪。 具体代码如下:

#include <QApplication>

#include <QCefContext.h>

#include "MainWindow.h"

int
main(int argc, char* argv[])
{
  QApplication a(argc, argv);

  // build QCefConfig
  QCefConfig config(argc, argv);
  config.setUserAgent("QCefViewTest");
  config.setLogLevel(QCefConfig::LOGSEVERITY_DEFAULT);
  config.setBridgeObjectName("CallBridge");
  config.setRemoteDebuggingPort(9000);

  // initialize QCefContext instance with config
  QCefContext cefContext(&a, &config);

  //这里创建就没问题
  QMainWindow * newWindow =new QMainWindow();
  QCefSetting settings;
  QCefView* view = new QCefView("https://www.baidu.com", &settings, newWindow);
  newWindow->setCentralWidget(view);
  newWindow->resize(1024,768);
  newWindow->show();

  QMainWindow w;
  QPushButton* btn = new QPushButton(&w);
  btn->setText("show in slots");
  btn->connect(btn, &QPushButton::clicked, [] {
    //这里创建一个新窗口,就显示不太正常
    QMainWindow * newWindow =new QMainWindow();
    QCefSetting settings;
    QCefView* view = new QCefView("https://www.baidu.com", &settings, newWindow);
    newWindow->setCentralWidget(view);
    newWindow->resize(1024,768);
    newWindow->show();
  });
  w.show();
  int rc = a.exec();

  return rc;
}


将QCefView放入dock一直闪烁

将QCefView放入ADS::DockWidget中后整个窗口一直闪烁,不能进行任何操作

我注释了QCefViewPrivate 386行恢复正常
if (now == q) {
// QCefView got focus, need to move the focus to the browser window
setFocus(true);
} else {
// Bug fix: #30
// When QCefView got focus then click if click some other widgets(for example a QLineEdit),
// the QCefView will not release the input focus, so we need to watch the focus change event.

// release the browser window focus status
setFocus(false);

// activate the top level window
// now->activateWindow();   <---------- 这里

}
这行代码好像导致了一直在丢失焦点。
注释是否有什么影响

浏览器获取焦点后不放,QT界面无法响应键盘事件

您好,我发现了一个问题
图片
如图,我打开一个百度搜索的界面,此时鼠标点击浏览器内的界面,浏览器获取焦点

然后我再点击QT界面的编辑框,此时光标在编辑框内,输入任何内容都无效,

按home 和 end 键,光标不会前后移动,反而是浏览器界面界面在上下移动

应该是键盘事件还被拿捏在cef里边,此时我如果想在界面输入内容,需要先切换到其他软件里,比如
图片

然后再回来点点编辑框就能输入内容了
图片

但是如果在浏览器页面中再次进行点击,就又会重现以上的问题。

我的系统是 win10 ,cef 版本用的里边自带的版本。 , 这个问题有解决办法吗?

我看到有一个类似的issues已关闭,但是我 qcefview 是刚git clone的最新版,似乎并没有解决

Grab the content of a QCefView (web page) and store it to a QImage

Dear developer,
I am trying to find a solution to how I can capture the QWidget (QCefView) content and save it in a QImage.
I tried with the typical "myWidget->grab()" function or the equivalent using a QPainter, but the result doesn't change:
I only get the background content of the QWidget but not the real content (web page).
Do you have any idea how to do this?

Thanks in advance.
J.

navigatetourl lead to a crash

  cefview = new CustomCefView(uri, this);
  cefview->navigateToUrl("http://www.baidu.com/");

[0820/163524.140:FATAL:cef_ref_counted.h(325)] Assert failed: ptr_ != 0.
QCefViewTest.exe has triggered a breakpoint.

I need navigateToUrl without constructor.

Qt端向JS端传递消息 方式优化

Qt端向JS端传递消息,有如下函数功能没有?直接执行JS回调
void WBWebViewComponent::CallBackToJs(const QString &function, const QString &arguments)
{
CefRefPtr frame =GetBrowser(m_browserHandlerIndex)->GetMainFrame();
QString datastr = QString("%1('").arg(function);
datastr += arguments;
datastr += "')";
CefString code;
//code.FromString(std::string(datastr.toLocal8Bit().data()));
code.FromString(datastr.toStdString());
frame->ExecuteJavaScript(code, frame->GetURL(), 0);
}

拖放功能异常(更新问题)

我当前使用的是cef_binary_89.0.12+g2b76680+chromium-89.0.4389.90_windows32这个版本,
发现DragEvent API 不能正常运行, 拖放目标到放置区域显示一个禁止的图标(见截图).
同样的页面, 在web浏览器是可以正常拖放的, 而且老版本的的cef也是支持拖放的.
avatar

STATIC_CRT设置为ON ,在VS2019编译demo不通过

您好:
我将QcefView里边的
option(STATIC_CRT "Use MultiThreaded linkage for MSVC" ON)
将QcefViewCore里边的
option(STATIC_CRT "Use MultiThreaded linkage for MSVC" ON)

环境变量指定 QTDIR = F:\QT\5.15.2static\msvc2019_64_static 【这个是我的QT静态编译的目录】

其他的没有修改,然后双击generate-win-proj.bat生成解决方案。

其他的项目能通过编译,但是demo失败:
图片

于是我按照文档里的说明自己新建一个demo项目去测试
`#include "myCef.h"
#include <QtWidgets/QApplication>
#include <QCefContext.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QCefConfig config(argc, argv);
config.setUserAgent("QCefViewTest");
config.setLogLevel(QCefConfig::LOGSEVERITY_VERBOSE);
config.setBridgeObjectName("CallBridge");
config.setRemoteDebuggingPort(9000);

QCefContext cefContext(&a, &config);

myCef w;
w.show();

int rc = a.exec();

return rc;

}
`
结果还是无法正常启动:
图片

请问应该怎样怎样正确的使用MT/MTD静态编译来运行demo

windows下无法正常退出应用

Qt版本是5.15.2_msvc2019,
Cef的版本是cef_binary_95.7.12+g99c4ac0+chromium-95.0.4638.54_windows32
集成之后, 调用qApp->quit()无法退出应用, 发现进程管理器里面应用还在.

Close application,crash

uri = QString("http://www.google.com");
cefview = new CustomCefView(uri,this);

when closed widget , crash
the tips is "FATAL:shutdown_checker.cc(52)] Check failed: !IsCefShutdown(). Object reference incorrectly held at CefShutdown",
but when I use the local page, no problem

InvokeMethod does not work with dict

Describe the bug
Dict info lost during message dispatch

To Reproduce
Call 'InvokeMethod' with a dict object:
ret = {data:"test"}; window.CallBridge.invokeMethod('TestMethod',ret)
Then a callback is triggered in 'MainWindow::onInvokeMethod', in this callback, I got a QVariantMap with the 'data' key, but the 'test' value was lost.

Further invistgate, in 'CefValueToQVariant', I got 'CefValueType::VTYPE_NULL' while deserializing the dict object.
However, in the 'V8ValueToCefValue' function, those values do exist.
So it seems dict content has been lost during SendProcessMessage, I cannot figure out why.

QCefViewTest.exe无法正常退出

编译QCefViewTest.exe,运行,然后关闭QCefViewTest.exe,看到:系统任务管理器里面仍然有一个QCefViewTest进程。

环境:
Qt版本: Qt\5.15.2\msvc2019_64
Cef:cef_binary_98.1.21+g9782362+chromium-98.0.4758.102_windows64.tar.bz2
vs2019
cmake 3.22.0

QCefView和QCefViewCore都是今天拉的最新版

Run javascript

Hi. I've found QCefView is very useful.
But I've problem.
I'm so beginner that I don't know how to run javascript code and return value from javascript.
When i using QWebEngineView class , following code runs well.

QWebEngineView mainWebView;
QWebEnginePage page = mainWebView.page();
page.runJavaScript("document.title", [](const QVariant &v) { qDebug() << v.toString(); });

Can i implement above action using QCefView instead of QWebEngineView?

Best regards.

您好,Linux环境下Qt生成的QCefViewTest不能执行

Linux下cmake生成的QCefViewTest使用命令可执行成功。但是使用qmake -project 生成的项目在Qt 中运行,生成的QCefViewTest使用./QCefViewTest 执行后失败,终端显示到 QFactoryLoader::QFactoryLoader() checking directory path "/home/zhaosz/work/library/QCefView/example/build-QCefViewTest-Desktop_Qt_5_12_10_GCC_64bit-Debug/styles" ... 卡着不动了。debug 项目时执行到main函数中的 QCefContext cefContext(&a, &config); 卡着不动。

image

CefBrowserHandler::OnBeforePopup

bool WBCefBrowserHandler::OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString &target_url, const CefString &target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures &popupFeatures, CefWindowInfo &windowInfo, CefRefPtr &client, CefBrowserSettings &settings, bool *no_javascript_access)
{
if (m_isNewPopup) {
//跳转到另外一个窗口打开,此窗口保持不变
emit onBeforePopupUrl(QString::fromStdString(target_url.ToString()));
return true;
}
switch (target_disposition)
{
case WOD_NEW_FOREGROUND_TAB:
case WOD_NEW_BACKGROUND_TAB:
case WOD_NEW_POPUP:
case WOD_NEW_WINDOW: {
//取消创建并在同一个browser打开
browser->GetMainFrame()->LoadURL(target_url);
return true;
}
}
return false;
}

链接QCefView.lib问题

您好,我现在链接了QCefView.lib但是编译时提示无法链接QCefConfig的构造函数等symbol,请问是什么原因呢
7E73C55C-D323-44a0-B295-BAA403957AA3

Cross-platform compilation on windows and linux for different architectures of cpu

Hello, I am currently compiling this project with source code, but I found that the cmake used in the construction project is only wini386/winx64/arch64/Linux x86_64/Linux aarch64 for linux and window. If I want the compiled library files or sample programs, it can be found in Other architectures such as running on mips, what needs to be done?
您好,目前正在用源码编译这个项目,但是我发现构建工程使用的cmake 关于linux和window只有wini386/winx64/arch64/Linux x86_64/Linux aarch64,如果我想要编译后的库文件或者示例程序能在其他架构比如mips上运行,需要怎样操作?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.