Unsolved ReferenceError: xxxx is not defined
-
@Digitale_GFacchini said in ReferenceError: xxxx is not defined:
edit_std_id
This id is defined in a Component so it is a separate entity. QML engine treats it as if it was a separate QML file (so your current file has no access to ids from there, only to exposed properties if any.
-
@sierdzio thaksthank you,
I suspected it.
I'm studying qt and c ++ recently. how can use , for example in a javascript or in evente clicked, edit_std_id.text? -
@Digitale_GFacchini said in ReferenceError: xxxx is not defined:
. how can use , for example in a javascript or in evente clicked, edit_std_id.text?
In your case, where it's ListView that creates instances (objects) from your component, you can do something like:
editfield.currentItem.text = "blah blah"
But you need to add "text" property to your component. Probably this would work:
Component { Item { id: item_row_edit property alias text: edit_std_id.text
Or the property needs to be in Component, not item, I'm not sure.
Notice, however, that ListView can create and destroy your delegate objects at any time. It is much better to populate your delagate data from model. And if you need to modify that data (like text in your example), you should modify the model - ListView will automatically update. More info on models and views in QML: https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html
-
@sierdzio hello, i have try use sistem with property alias.
If i put it between component and itemComponent { id: delegate property alias aedit_std_id: edit_std_id.text Item { id: item_row_edit
In this mode component not load
If i put the row definition property after declare item so:
Item { id: item_row_edit property alias aedit_std_id: edit_std_id.text
A have the original error: aedit_std_id is not defined
-
OK, then put your component in another QML file.
-
@sierdzio hello, i have create a file MyDelagateFieldEdit
Item { id: rootDelegate RowLayout { id: row_id x: 7 y: 9 height: 36 Text { id: lbl_id width: 120 height: 20 text: qsTr("ID : ") verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignRight font.pixelSize: 14 Layout.fillWidth: false Layout.fillHeight: false Layout.minimumWidth: 120 font.bold: true } Rectangle { id: rect_txt_id width: 108 height: 28 radius: 1 border.width: 1 border.color: "#a5aefa" anchors.leftMargin: 8 anchors.left: lbl_id.right TextInput { id: edit_std_id height: 22 text: std_id anchors.margins: 4 font.pixelSize: 14 cursorVisible: true antialiasing: true anchors.fill: parent clip: true inputMask: qsTr("") horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter } } } RowLayout { id: row_nome parent: rootDelegate height: 36 anchors.top: row_id.bottom anchors.topMargin: 6 anchors.right: parent.right anchors.rightMargin: 20 anchors.left: parent.left anchors.leftMargin: 20 Text { id: lbl_nome width: 120 height: 20 text: qsTr("Nome : ") Layout.minimumWidth: 120 Layout.fillHeight: false Layout.fillWidth: false font.bold: true horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter font.pixelSize: 14 } Rectangle { id: rect_txt_nome width: 408 height: 28 border.width: 1 border.color: "#a5aefa" radius: 2 Layout.minimumWidth: 408 anchors.left: lbl_nome.right anchors.leftMargin: 8 TextInput { id: edit_std_nome width: 400 height: 22 text: std_nome anchors.margins: 4 anchors.fill: parent antialiasing: true horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter clip: true cursorVisible: true inputMask: qsTr("") font.pixelSize: 14 } } } RowLayout { id: row_cognome parent: rootDelegate height: 36 anchors.top: row_nome.bottom anchors.topMargin: 6 anchors.right: parent.right anchors.rightMargin: 20 anchors.left: parent.left anchors.leftMargin: 20 Text { id: lbl_cognome width: 120 height: 20 text: qsTr("Cognome : ") Layout.minimumWidth: 120 horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter font.bold: true font.pixelSize: 14 } Rectangle { id: rect_txt_cognome width: 408 height: 28 border.width: 1 border.color: "#a5aefa" radius: 4 Layout.minimumWidth: 408 anchors.left: lbl_cognome.right anchors.leftMargin: 8 TextInput { id: edit_std_cognome width: 400 height: 22 text: std_cognome anchors.margins: 4 anchors.fill: parent antialiasing: true horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter clip: true cursorVisible: true font.pixelSize: 14 inputMask: qsTr("") } } } RowLayout { id: row_luogonascita parent: rootDelegate height: 36 anchors.right: parent.right anchors.rightMargin: 20 anchors.left: parent.left anchors.leftMargin: 20 anchors.top: row_cognome.bottom anchors.topMargin: 6 anchors.bottomMargin: 25 Text { id: lbl_luogonascita width: 120 height: 20 text: qsTr("Luogo Nascita : ") Layout.minimumWidth: 120 horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter font.bold: true font.pixelSize: 14 } Rectangle { id: rect_txt_luogonascita width: 408 height: 28 border.width: 1 border.color: "#a5aefa" radius: 2 Layout.minimumWidth: 408 anchors.left: lbl_luogonascita.right anchors.leftMargin: 8 TextInput { id: edit_std_luogonascita height: 22 text: std_luogonascita anchors.margins: 4 anchors.fill: parent antialiasing: true horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter clip: true cursorVisible: true font.pixelSize: 14 inputMask: qsTr("") } } } }
In file edit.qml i have changed call delegate into ListView
ListView { id: editfield height: 150 contentHeight: 150 anchors.top: rowHeader.bottom anchors.bottomMargin: 50 model: myModelEdit delegate: MyDelagateFieldEdit {} }
Don't i have problem with data from model into every field into MyDelagateFieldEdit, for example "edit_std_id" or "edit_std_name", but when i want read data for update database I always have the same error.
ReferenceError: edit_std_nome is not defined
-
@Digitale_GFacchini said in ReferenceError: xxxx is not defined:
but when i want read data for update database I always have the same error.
where are you trying to read that data?
-
@sierdzio when clicked button confirm in file edit.qml
I need to pass data to the function that will update the database -
I mean where in code :-) Please paste the relevant piece of the code.
-
@sierdzio hello, I stay try another way. if result ok i put solution. If not correct i public all code.
-
@sierdzio Hello,
aving found no indication of how it can access from a file (edit.qml) to the values of the elements assigned in a delegate (MyDelagateFieldEdit.qml) I have applied the following method to read the data that are modified and then update the record.http://imaginativethinking.ca/bi-directional-data-binding-qt-quick/bidirectionalbindingsample_1/
In my exercise program, however, I have only 3 fields to manage. I do not think it's the right way to handle data editing.
There is no one who has an example of a program with a list and management of data detail?
Yet it is a classic management program. -
Here's some code that might help you https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel-subclass
Yet it is a classic management program.
Qt has no problem supporting that use case. It just requires some coding and getting used to. The model-view infrastructure is very flexible which also makes it a bit complex. Once you get to know it, though, it will be quite easy to work with.