QT WebView/WebKit 问题

QT WebView/WebKit issue

我正在尝试将 WebView 添加到我的 GUI。首先,应用程序每次都意外崩溃。我认为我可能需要将 WebKit 3.0 与 WebView 1.1 一起导入。添加所需的导入语句后,我尝试 运行 但它说 module "QtWebKit" is not installed。我检查了 include 文件夹,它确实不存在。 所以我的问题是如果 QtWebKit 是我需要的,我该如何安装它?

更新: 当此代码存在于我的 .qml 文件中时,应用程序在未启动的情况下崩溃:

WebEngineView{
            anchors.fill: parent
            url: "http://www.google.com"
        }

这是我在 QT 5.6 上使用的导入语句:

import QtWebEngine 1.1

这是由于存在上述代码而产生的段错误:

完整的演示代码:

import QtQuick 2.6
import QtQuick.Controls 1.5 as QC
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import QtQuick.Dialogs 1.2
import QtMultimedia 5.6
import Qt.labs.controls 1.0
import QtWebEngine 1.2

ApplicationWindow {
    height: 640
    width: 480
    visible: true
    Loader{
        anchors.fill: parent
        sourceComponent: webComponent
    }
    Component{
        id: webComponent
        WebEngineView{
            anchors.fill: parent
            id: web
            profile: WebEngineProfile {
                storageName: "Default"
            }
        }
    }
}

Qt WebKit 是 deprecated module. Maybe you can install it from Qt sources, but since you want to use WebView 1.1 (and that you're on Qt5.6), I think you'd better use Qt WebEngine(不推荐使用已弃用的模块)。 您已经可以在您的文件夹中看到它(模块 QtWebEngine 和 QtWebView)。

您的调试器的堆栈跟踪显示您的崩溃发生在 Qt 的 OpenGL 函数中。请记住在开始使用 Qt WebEngine 之前调用 QtWebEngine::initialize()

另请注意:

  • Qt WebView 是 运行 您的移动设备 OS 的本机 Web 引擎的轻量级模块。它的主要 QML 类型称为 WebView.
  • Qt WebKit 是 运行 完全独立的 Web 引擎的重量级模块。它的主要QML类型也叫WebView,但这与另一个WebView完全无关。此模块现已弃用。
  • Qt WebEngine 是 运行 完全独立的 Web 引擎的重量级模块。它的主要 QML 类型称为 WebEngineView。该模块旨在取代 Qt WebKit。