Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Quick 2.0 import delegate
Qt 6.11 is out! See what's new in the release blog

Quick 2.0 import delegate

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schneidi
    wrote on last edited by
    #1

    Hey I have the following code.
    And I didn't manage to import a delegate from a file.
    I get the Error
    @views/GridView.qml:19: ReferenceError: Elements is not defined@

    main.qml
    @
    import "views"

    Item {
    width: 700
    height: 360
    Rectangle {
    anchors.fill: parent
    GridView {
    anchors.fill: parent
    }
    }
    }@

    views/GridView.qml
    @import QtQuick 2.0
    import "../elements/" as Elements
    Item {
    id: grid_view
    width: 100
    height: 62
    Rectangle {
    id: grid_view_bg
    anchors.fill: parent
    ListView {
    anchors.fill: parent
    model: employee_model
    orientation: Qt.Horizontal
    delegate: Elements.EmployeeDelegate
    }
    }
    }@

    elements/EmployeeDelegate.qml
    @import QtQuick 2.0

    Component {
    Item {
    id:employeeContainer
    width: 180;
    height: parent.height
    Rectangle {
    id:employeeBody
    anchors.fill: parent
    anchors.rightMargin: 5
    color: "red"
    border.color: "black"
    Rectangle {
    id: employeeHeader
    color: "#bbdbf3"
    anchors.horizontalCenter: parent.horizontalCenter
    width: parent.width
    height: 40

                Text {
                    anchors.centerIn: parent
                    text: '<b>Name:</b> ' + employee.name
                }
                border.color: "black"
            }
            Item {
                id: clipContainer
                anchors.top: employeeHeader.bottom
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                width: parent.width
                Rectangle {
                    id: clip_container_bg
                    anchors.fill: parent
                    border.color: "black"
                }
                ListView {
                    id:clipList
                    anchors.fill: parent
                    model: clip_model
                    delegate: clipDelegate
                    onModelChanged: {
                        console.debug(clip_model);
                    }
                }
            }
        }
    }
    

    }
    @

    If I change the GridView.qml to
    @
    import "../elements/"
    @

    I get an Error like
    @views/GridView.qml:19: ReferenceError: EmployeeDelegate is not defined@

    How am I supposed to set Delegates to a List view that are defines in a qml file ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      solution 1.
      put your qml files into Qt resource system.
      solution 2
      copy your qml files to the folder in which your program is executed.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved