CefView / QCefView

A Qt Widget encapsulated CEF view based on QWidget
https://cefview.github.io/QCefView/
GNU Lesser General Public License v2.1
546 stars 144 forks source link

Delete cefview ,crash #2

Closed Liminglyq closed 2 years ago

Liminglyq commented 3 years ago

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

xp19870106 commented 3 years ago

@tishion when can this bug be solved? by the way, are u chinese? I saw you reply someone in chinese

xp19870106 commented 3 years ago

There's a problem in these code `void CefViewBrowserHandler::CloseAllBrowsers(bool force_close) { // If all browsers had been closed, then return std::uniquelockstd::mutex lock(mtx); if (!browsercount) { return; }

// Flip the closing flag isclosing = true;

// Close all popup browsers if any if (!popup_browserlist.empty()) { for (auto it = popup_browserlist.begin(); it != popup_browserlist.end(); ++it) { if (!(it)) continue; auto host = (it)->GetHost(); if (!host) continue; host->CloseBrowser(force_close); } }

if (mainbrowser) { // Request that the main browser close. auto host = mainbrowser->GetHost(); if (host) mainbrowser->GetHost()->CloseBrowser(force_close); }

if (!CefCurrentlyOn(TID_UI)) { // if we are not in browser main thread we need to wait for // all browsers to be closed, while (browsercount) cv_allclosed.wait(lock); } }`

you need to change the code as below, or the void CefViewBrowserHandler::OnBeforeClose(CefRefPtr browser) won't be called

`void CefViewBrowserHandler::CloseAllBrowsers(bool force_close) { // If all browsers had been closed, then return std::uniquelockstd::mutex lock(mtx); if (!browsercount) { return; }

// Flip the closing flag isclosing = true;

// Close all popup browsers if any if (!popup_browserlist.empty()) { for (auto it = popup_browserlist.begin(); it != popup_browserlist.end(); ++it) { if (!(it)) continue; auto host = (it)->GetHost(); if (!host) continue; ::SetParent(host->GetWindowHandle(), NULL); host->CloseBrowser(force_close); } }

if (mainbrowser) { // Request that the main browser close. auto host = mainbrowser->GetHost(); if (host){ ::SetParent(mainbrowser->GetHost()->GetWindowHandle(), NULL); mainbrowser->GetHost()->CloseBrowser(force_close); } }

if (!CefCurrentlyOn(TID_UI)) { // if we are not in browser main thread we need to wait for // all browsers to be closed, while (browsercount) cv_allclosed.wait(lock); } }`

@tishion

tishion commented 3 years ago

i will try to fix this problems later (maybe in June or July), currently i have no time to work on this, sorry.

yes, I am Chinese.

xp19870106 commented 3 years ago

@tishion 太棒了,不用再说蛋疼的英语了。还有个问题,就是开了一个CefWiew之后,关闭再重新开一个会崩溃,我看了下,是QCefManager里面uninitializeCef里面的releaseCef()调用之后,再次调用initializeCef()里面的if (!CefInitialize(main_args, cefsettings, app_, sandboxInfo))崩溃掉了,如果可以一起修复了吧。 辛苦啦!!

tishion commented 3 years ago

这个问题属于已知设计问题,但是现在确实没时间去改。

xp19870106 commented 3 years ago

@tishion 可以禁用cefview吗?就是让鼠标交互无效

xp19870106 commented 3 years ago

@tishion 还有一个问题,就是我在创建qcefview的时候不指定url,后面调用navigatetourl方法,会崩溃,因为 pQCefViewHandler_->GetBrowser()->GetMainFrame()->LoadURL(data); 这里拿到的GetBrowser为空,只有当页面已经显示后调用navigatetourl方法才正常

stevezhougs commented 3 years ago

QCefViewTest,how to exit the app? When I click close the QCefViewTest's windows,the app still running.

Fishguys commented 3 years ago

QCefViewTest,how to exit the app? When I click close the QCefViewTest's windows,the app still running.

when you close the QCefViewTest's windows, QCefViewTest's top level window ::SendMessage(hWnd, WM_CLOSE, 0, 0);

tishion commented 2 years ago

Duplicate of #24