如果在QWidget中创建QQuickWidget,则Qt qml崩溃

时间:2019-02-23 14:25:23

标签: qt qml

有一个奇怪的问题,也可能是一个错误,但是在发布该错误之前,我想先保证一下-否则会发现我自己的错误。基本上,我想创建一个QWidget子类,其中包含一个QQuickWidget和其他qml加载一个url文件。 我可以将崩溃分解为以下最低版本。仅发生崩溃

  • 如果qml实际上设置了loadhtml或调用了QQuickWidget,则 AND
  • 如果QT += core gui widgets qml quickwidgets webview TARGET = webviewcrash TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++11 CONFIG += qml_debug SOURCES += main.cpp RESOURCES += res.qrc 是在查看器的构造函数中创建的。

如果在没有父级的情况下初始化QQuickWidget,它甚至都不会起作用。 要进行复制,请运行该应用程序,然后通过系统任务栏中的绿色图标将其关闭。

crashtest.pro

#include <QApplication>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QtWebView>
#include <QWebSocketServer>
#include <QQuickWidget>
#include <qboxlayout.h>
#include <qqmlapplicationengine.h>
#include <QQuickView>
#include <QtQml/QQmlContext>
#include <QDebug>

class Viewer : public QWidget
{
    Q_OBJECT
public:
    explicit Viewer(QWidget *parent = nullptr) : QWidget(parent){
        setLayout(new QVBoxLayout);
    }
    void init(QQuickWidget* viewer){
        if ( viewer ){
            this->layout()->addWidget(viewer);
        }
        else{
            QQuickWidget* viewer = new QQuickWidget(this);
            viewer->setSource(QUrl("qrc:/viewer.qml"));
            viewer->setResizeMode(QQuickWidget::SizeRootObjectToView);
            this->layout()->addWidget(viewer);
        }
    }
};

#include "main.moc"

#define TRY_VIEWER_INIT_WITH_POINTER 0 // Crash
#define TRY_VIEWER_INIT_WITH_REFERENCE 0 // OK
#define TRY_VIEWER_INIT_INSIDE_VIEWER 0 // Crash
#define TRY_STAND_ALONE 0 // Crash
#define TRY_WITHOUT_QQUICKWIDGET 0 // OK - but this is a qml ApplicationWindow, not an Item.

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

#if TRY_VIEWER_INIT_WITH_POINTER
    auto v1 = new Viewer();
    v1->resize(500,300);
    v1->move(100,100);
    v1->show();
    QQuickWidget *v1_viewer = new QQuickWidget;
    v1_viewer->setResizeMode(QQuickWidget::SizeRootObjectToView);
    v1_viewer->setSource(QUrl("qrc:/viewer.qml"));
    v1->init(v1_viewer);
#endif

#if TRY_VIEWER_INIT_WITH_REFERENCE
    auto v1 = new Viewer();
    v1->resize(500,300);
    v1->move(100,100);
    v1->show();
    QQuickWidget v1_viewer;
    v1_viewer.setResizeMode(QQuickWidget::SizeRootObjectToView);
    v1_viewer.setSource(QUrl("qrc:/viewer.qml"));
    v1->init(&v1_viewer);
#endif

#if TRY_VIEWER_INIT_INSIDE_VIEWER
    auto v1 = new Viewer();
    v1->resize(500,300);
    v1->move(100,100);
    v1->show();
    v1->init(nullptr);
#endif

#if TRY_STAND_ALONE
    QQuickWidget viewer;
    viewer.setSource(QUrl("qrc:/viewer.qml"));
    viewer.setResizeMode(QQuickWidget::SizeRootObjectToView);
    viewer.show();
#endif

#if TRY_WITHOUT_QQUICKWIDGET
    QQmlApplicationEngine engine;
    engine.load(QUrl("qrc:/viewer2.qml"));
    if (engine.rootObjects().isEmpty())
        return -1;
#endif

    // MENU
    QMenu trayMenu;
    QSystemTrayIcon tray;
    trayMenu.addAction("Exit",[&](){
        qApp->quit();
    });
    tray.setContextMenu(&trayMenu);
    QPixmap pix(32,32);
    pix.fill(QColor(Qt::green));
    tray.setIcon(QIcon(pix));

    return a.exec();
}

main.cpp:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtWebView 1.1

Item {
    WebView{
        id: webView
        anchors.fill: parent
        // Crash on app exit, if you uncomment this line:
        //url: "https://www.qt.io"
    }
    Component.onCompleted: {
        // Crash on app exit, if you uncomment this line:
        webView.loadHtml("<html><head></head><body>Simple body</body></html>","")
    }
}

viewer.qml

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtWebView 1.1

ApplicationWindow {
    visible: true
    x: 100
    y: 100
    width: 500
    height: 400
    WebView{
        id: webView
        anchors.fill: parent
        // Crash on app exit, if you uncomment this line:
        //url: "https://www.qt.io"
    }
    Component.onCompleted: {
        // Crash on app exit, if you uncomment this line:
        webView.loadHtml("<html><head></head><body>Simple body</body></html>","")
    }
}

viewer2.qml

[11328:19036:0223/150952.613:FATAL:render_process_host_impl.cc(887)] Check failed: map_.empty(). 
Backtrace:
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11B4E857+810583]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11B5BD11+865041]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11A93A9E+45214]
    QtWebEngineCore::JavaScriptDialogController::qt_static_metacall [0x1166ED0A+32480538]
    QtWebEngineCore::JavaScriptDialogController::qt_static_metacall [0x1167185F+32491631]
    GetHandleVerifier [0x12ED8CE9+20263193]
    IsSandboxedProcess [0x1403328B+16485723]
    IsSandboxedProcess [0x13A93802+10588882]
    IsSandboxedProcess [0x1406445F+16686895]
    IsSandboxedProcess [0x14063EDD+16685485]
    QtWebEngineCore::JavaScriptDialogController::qt_static_metacall [0x10406C6D+13180029]
    QtWebEngineCore::JavaScriptDialogController::qt_static_metacall [0x10406C41+13179985]
    IsSandboxedProcess [0x13D95555+13742117]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11AC020E+227342]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11AC0148+227144]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11ABF94F+225103]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11ABF96F+225135]
    QWebEngineUrlSchemeHandler::_q_destroyedUrlSchemeHandler [0x11ABFA2C+225324]
    QtWebEngineCore::JavaScriptDialogController::qt_static_metacall [0x1115CC69+27163769]
    QtWebEngineCore::ProfileAdapterClient::downloadInterruptReasonToString [0x0F70855F+2623]
    QtWebEngineCore::ProfileAdapterClient::downloadInterruptReasonToString [0x0F7086A6+2950]
    QtWebEngineCore::ProfileAdapterClient::downloadInterruptReasonToString [0x0F70888F+3439]
    QtWebEngineCore::ProfileAdapter::checkPermission [0x0F705B56+230]
    QtWebEngineCore::FilePickerController::mode [0x0F71EDBA+33066]
    QtWebEngineCore::ProfileAdapter::~ProfileAdapter [0x0F7054E6+246]
    QtWebEngineCore::ProfileAdapter::~ProfileAdapter [0x0F7055DD+493]
    QtWebEngineCore::WebEngineSettings::setWebContentsAdapter [0x0F69BCEA+3418]
    QtWebEngineCore::WebContentsAdapter::requestedUrl [0x0F741E5A+746]
    QWebEngineUrlScheme::operator!= [0x0F74BB8B+3707]
    QWebEngineUrlScheme::operator!= [0x0F74BCB7+4007]
    QTextCodec::codecForHtml [0x5F98A3C2+3390559]
    QTreeViewPrivate::layout [0x609525D6+456449]
    main [0x001F6D24+628] (d:\anonymous\qml-user-js-crash\userjs\main.cpp:67)
    WinMain [0x001F664D+173] (c:\users\qt\work\qt\qtbase\src\winmain\qtmain_win.cpp:104)
    invoke_main [0x001F50AE+30] (d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:107)
    __scrt_common_main_seh [0x001F4F47+343] (d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
    __scrt_common_main [0x001F4DDD+13] (d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
    WinMainCRTStartup [0x001F5128+8] (d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp:17)
    BaseThreadInitThunk [0x7694343D+18]
    RtlInitializeExceptionChain [0x776A9802+99]
    RtlInitializeExceptionChain [0x776A97D5+54]

我正在Win7桌面上使用Qt5.12.0,并且使用的编译器是MSVC2017 32位。

这是回溯:

Command

0 个答案:

没有答案