使用 QtWebEngine 退出时 QT 崩溃

QT Crash on exit with QtWebEngine

所以我在我的 QML 中使用 WebEngineView 是这样的:

...
Loader {
    // some properties
    sourceComponent: WebEngineView {
        ...
    }
}

在 C++ 逻辑中,我在构造函数和析构函数中使用 QQuickWebEngineProfile::defaultProfile()

MainViewModel(QObject* parent) : QObject(parent)
{
    // using QQuickWebEngineProfile::defaultProfile();
    // getting cookieStore of the profile and connect it to some slots
}

~MainViewModel()
{
    // using QQuickWebEngineProfile::defaultProfile();
    // getting cookieStore of the profile and disconnect it from MainViewModel
}

所以它工作得很好,但是当我试图关闭我的应用程序时 (调用 qApp->quit()),它崩溃了。如果我从 QML 中删除 WebEngineView 它会起作用,如果我在 c++ 中删除 defaultProfile() 的使用它会起作用。但是我需要这些东西。

转储:

1  _threadid                                                                                                                                        ucrtbased                    0x7ffb48687c75 
2  _threadid                                                                                                                                        ucrtbased                    0x7ffb48687e13 
3  abort                                                                                                                                            ucrtbased                    0x7ffb4869e01d 
4  `anonymous namespace'::messageHandler                                                                                                            application.cpp         46   0x7ff7c2d2b1bf 
5  qt_message_print                                                                                                                                 qlogging.cpp            1844 0x7ffb08317fdf 
6  qt_message                                                                                                                                       qlogging.cpp            379  0x7ffb08318657 
7  QMessageLogger::fatal                                                                                                                            qlogging.cpp            890  0x7ffb08316612 
8  qt_assert                                                                                                                                        qglobal.cpp             3354 0x7ffb08307a48 
9  QAccessible::registerAccessibleInterface                                                                                                         qaccessible.cpp         747  0x7ffb01df22bd 
10 QAccessible::uniqueId                                                                                                                            qaccessible.cpp         767  0x7ffb01df2247 
11 QQuickWebEngineViewPrivate::widgetChanged                                                                                                        qquickwebengineview.cpp 982  0x7ffb4b2b5bda 
12 QQuickWebEngineViewPrivate::bindViewAndWidget                                                                                                    qquickwebengineview.cpp 972  0x7ffb4b2b5b6e 
13 QQuickWebEngineViewPrivate::releaseProfile                                                                                                       qquickwebengineview.cpp 200  0x7ffb4b2b2349 
14 QtWebEngineCore::ProfileAdapter::~ProfileAdapter                                                                                                 profile_adapter.cpp     127  0x7ffad4237f20 
15 QtWebEngineCore::ProfileAdapter::`vector deleting destructor'                                                                                    Qt5WebEngineCored            0x7ffad4238678 
16 std::default_delete<QtWebEngineCore::DevToolsFrontendQt::NetworkResourceLoader>::operator()                                                      memory                  1758 0x7ffad41d9a75 
17 std::unique_ptr<QtWebEngineCore::WebChannelIPCTransportHost,std::default_delete<QtWebEngineCore::WebChannelIPCTransportHost>>::reset             memory                  1910 0x7ffad4287857 
18 QtWebEngineCore::WebEngineContext::destroy                                                                                                       web_engine_context.cpp  339  0x7ffad4295a87 
19 QtWebEngineCore::WebEngineContext::destroyContextPostRoutine                                                                                     web_engine_context.cpp  425  0x7ffad4295bf8 
20 qt_call_post_routines                                                                                                                            qcoreapplication.cpp    336  0x7ffb087276ef 
21 QApplication::~QApplication                                                                                                                      qapplication.cpp        714  0x7ffb07767046 
  ...
30 main                                                                                                                                             main.cpp                63   0x7ff7c21d4640 

它试图访问当时已被删除的主 window。为了解决这个问题,我不得不推迟销毁我的主 window。我用

完成了
QObject::deleteLater()