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. ReferenceError: xxxx is not defined
Forum Updated to NodeBB v4.3 + New Features

ReferenceError: xxxx is not defined

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
13 Posts 2 Posters 9.3k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    @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.

    (Z(:^

    D 1 Reply Last reply
    2
    • sierdzioS sierdzio

      @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.

      D Offline
      D Offline
      Digitale_GFacchini
      wrote on last edited by
      #3

      @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?

      sierdzioS 1 Reply Last reply
      0
      • D Digitale_GFacchini

        @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?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        @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

        (Z(:^

        D 1 Reply Last reply
        0
        • sierdzioS sierdzio

          @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

          D Offline
          D Offline
          Digitale_GFacchini
          wrote on last edited by
          #5

          @sierdzio hello, i have try use sistem with property alias.
          If i put it between component and item

          Component {
                      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

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #6

            OK, then put your component in another QML file.

            (Z(:^

            D 1 Reply Last reply
            0
            • sierdzioS sierdzio

              OK, then put your component in another QML file.

              D Offline
              D Offline
              Digitale_GFacchini
              wrote on last edited by
              #7

              @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
              
              sierdzioS 1 Reply Last reply
              0
              • D Digitale_GFacchini

                @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
                
                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #8

                @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?

                (Z(:^

                D 1 Reply Last reply
                0
                • sierdzioS sierdzio

                  @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?

                  D Offline
                  D Offline
                  Digitale_GFacchini
                  wrote on last edited by Digitale_GFacchini
                  #9

                  @sierdzio when clicked button confirm in file edit.qml
                  I need to pass data to the function that will update the database

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #10

                    I mean where in code :-) Please paste the relevant piece of the code.

                    (Z(:^

                    D 2 Replies Last reply
                    0
                    • sierdzioS sierdzio

                      I mean where in code :-) Please paste the relevant piece of the code.

                      D Offline
                      D Offline
                      Digitale_GFacchini
                      wrote on last edited by
                      #11

                      @sierdzio hello, I stay try another way. if result ok i put solution. If not correct i public all code.

                      1 Reply Last reply
                      1
                      • sierdzioS sierdzio

                        I mean where in code :-) Please paste the relevant piece of the code.

                        D Offline
                        D Offline
                        Digitale_GFacchini
                        wrote on last edited by
                        #12

                        @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.

                        1 Reply Last reply
                        0
                        • sierdzioS Offline
                          sierdzioS Offline
                          sierdzio
                          Moderators
                          wrote on last edited by
                          #13

                          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.

                          (Z(:^

                          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