0
votes

I have a tableview and I want to open a dialog box on onPressAndHold on a row and display the value of the cell of the row "orderNumber". But i get the Error message: ReferenceError: row is not defined

TableView {
    id: tableviewopenorders
    height: 180
    clip: false
    visible: true

    onPressAndHold: oocanceldialog.open()


    TableViewColumn {
        id: orderNumberColumn
        role: "orderNumber"
        title: "Order Number"
    }

    model: openordersModel
}

ListModel {
    id: openordersModel

    ListElement {
        orderNumber: "1223455"

    }
    ListElement {
        orderNumber: "111111"

    }
}


Dialog {
    id: oocanceldialog
    title: "Cancel confirmation"
    standardButtons: Dialog.Ok | Dialog.Cancel
    x: (parent.width - width) / 2
    y: (parent.height - height) / 2
    Label {
        text: openordersModel.get(row).orderNumber

    }

    onAccepted: console.log("Ok clicked")
    onRejected: oocanceldialog.close()
}
1
I'm not familiar with this language, but intuitively, it looks like there is nothing in your code that would set row in the expression openordersModel.get(row).orderNumber. Is that the line causing the error? Is there an event handler for clicking on individual rows vs clicking on the table itself? Maybe try looking for something like that?killthrush
yes thats the line causing the error. For example when i replace the onPressAndHold: oocanceldialog.open() with onPressAndHold:console.log(openordersModel.get(row).orderNumber) the I got the correct output printed when i press and hold on the first row i got the 1223455 and when i press and hold on the second row then i got 111111 printed.. But this line is not working when its outside the tableview contextSebastian Walecko
I wonder how do you think the dialog will get the row. Add property int row to the dialog and so set it from pressandhold handler before opening that.folibis
No, no ... try mine :-)folibis

1 Answers

0
votes

row exists in the context of onPressAndHold, so it does not exist outside of it, to get the row we must use the currentRow attribute of the TableView:

currentRow : int

The current row index of the view. The default value is -1 to indicate that no row is selected.

In your case:

Label {
    text: openordersModel.get(tableviewopenorders.currentRow).orderNumber
}