【问题标题】:module `Qt.labs.qmlmodels` is not installed未安装模块“Qt.labs.qmlmodels”
【发布时间】:2022-11-11 12:58:07
【问题描述】:

我正在尝试运行example of item selection for a TableView,但它需要Qt.labs.qmlmodels。问题是,它似乎没有安装,我找不到正确的包。

main.qml:

import Qt.labs.qmlmodels
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ApplicationWindow {
    visible: true
    width: 1000
    height: 700
    title: "Test"

    TableView {
        id: tableView

        anchors.fill: parent
        clip: true

        model: TableModel {
            rows: [{
                "name": "Harry"
            }, {
                "name": "Hedwig"
            }]

            TableModelColumn {
                display: "name"
            }

        }

        selectionModel: ItemSelectionModel {
            model: tableView.model
        }

        delegate: Rectangle {
            required property bool selected

            implicitWidth: 100
            implicitHeight: 30
            color: selected ? "blue" : "lightgray"

            Text {
                text: display
            }

        }

    }

}

main.py:

import sys
import signal

from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine

# Make app respond to Ctrl-C
signal.signal(signal.SIGINT, signal.SIG_DFL)

app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)  # type: ignore

engine.load("main.qml")

sys.exit(app.exec())

运行 main.py 给我这个错误:

QQmlApplicationEngine failed to load component
file:///home/user/test2/main.qml:1:1: module "Qt.labs.qmlmodels" is not installed
  • 操作系统:Arch Linux
  • Qt 版本:6.3.1-1

【问题讨论】:

    标签: python qt qml qtquick2 archlinux


    【解决方案1】:

    请阅读这个: [qt-6.4-qml-python-missing-liberary-module-qt5compat-graphical-effects-is-not-installed][1] [1]:https://www.it-hinca.de/de/blog/blog-news/qt-6-4-qml-python-missing-liberary-module-qt5compat-graphical-effects-is-not-安装的.html

    刚才,我尝试更改 matplotlib-backends 的版本。我发现pyqt6文件夹没有Qt文件夹。 所以我将 pyside6 lib 中的内容复制到 pyqt lib。

    对我来说是:从D:PythonPython39Libsite-packagesPySide6qmlQtD:PythonPython39Libsite-packagesPyQt6Qt6qml

    请试试这个,希望它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-08
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      • 2019-07-19
      • 2016-02-19
      • 2021-05-23
      相关资源
      最近更新 更多