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. ListModel javascript functor storage

ListModel javascript functor storage

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 549 Views
  • 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.
  • D Offline
    D Offline
    drakebp
    wrote on last edited by
    #1

    I am still quite new to qt/qml and javascript so this might be newbie question. I have a situation where I have an application that has data stored in a ListModel, when the ListView that owns the model updates an item in the model I want to call a functor that will update the value in a couple places, but every time I try to run the functor stored in the model I get a type error.

    @
    qrc:///main.qml:50: TypeError: Type error
    qrc:///main.qml:50: TypeError: Type error
    qrc:///main.qml:50: TypeError: Type error
    @

    Here is a demo of the issue. I created it using default Qt Quick application in Qt Creator. I am using Qt 5.3.1.

    @
    import QtQuick 2.2
    import QtQuick.Window 2.1

    Window {
    visible: true
    width: 360
    height: 360

    property int value1: 5
    property int value2: 6
    property int value3: 7
    
    Component.onCompleted: {
        function Func(n) {
            return function(i) {
                value1 = i;
                return "This is cell: " + i + " and is associated to property that had value: " + n;
            }
        };
    
        view.model.append( { func : new Func(value1) } );
        view.model.append( { func : new Func(value2) } );
        view.model.append( { func : new Func(value3) } );
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    
    ListView {
        id: view
        anchors.fill: parent
    
        model: ListModel {}
        delegate: Component {
    
            Rectangle {
                width: view.width
                height: 25
                color: "red"
                border.color: "black"
    
                Text {
                    id: test
                    text: {
                        var test = model.func;
                        test(index);
                    }
                }
            }
        }
    }
    

    }

    @

    There might be better ways to do this, but I would still like to know what I am doing wrong. Thanks

    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