Skip to content

Handling of slice of struct declared in main package #160

Open
@cjslep

Description

@cjslep

I was trying my hand at creating a dynamically-populated table from data in go, when I got a please report to the developers error:

panic: handling of []main.ColumnHeader (&[]main.ColumnHeader{main.ColumnHeader{Text:"Test text header", Role:"sign", Kind:3}, main.ColumnHeader{Text:"Bool Header", Role:"isok", Kind:0}, main.ColumnHeader{Text:"Integer", Role:"num", Kind:1}}) is incomplete; please report to the developers

I am basically trying to access the following struct definitions with test data:

type TableData struct {
    Cols    int
    Rows    int
    Headers []ColumnHeader
    Data    [][]CellData
}

type ColumnHeader struct {
    Text string
    Role string
    Kind int
}

type CellData struct {
    Role        string
    Editable    bool
    ValueBool   bool
    ValueInt    int
    ValueString string
}

The registration on the go side to make it accessible:

func main() {
    // ...
    engine := qml.NewEngine()
    context := engine.Context()
    // Define the value to share to QML
    tableModel := TableData {
        // Lots of handrolled test data
    }
    context.SetVar("tableData", &tableModel)
    // ...
}

The basic QML:

TableView {
    id: root
    Component.onCompleted: {
        function refresh() {
            // ...
            for (var i = 0; i < adminModel.cols; i++) {
                root.addColumn(columnPrototype.createObject(root, {"title": tableModel.headers[i].text, "role": tableModel.headers[i].role, "goType": tableModel.headers[i].kind}))
            }
            // ...
        }
    }
    Component {
        id: columnPrototype
        TableViewColumn {
            width: 125
        }
    }
}

I looked into other API calls to see if I was doing something incorrect. Nothing seemed obvious to me. The only thing slightly relevant could be registering the ColumnHeader go type, but I am not instantiating new copies of that struct on the qml side. I have another data type (lets call it AppSettings) that is SetVard similarly but does not have any interactions with TableViews. AppSettings also contains a slice of structs from a different package that is nothing but a struct of primitives, and it seems to do fine, so I am slightly baffled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions