Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-121946

scoped enum values cannot be used as keys in a JS object

    XMLWordPrintable

Details

    • 1e6cb2462 (dev), 460f8e4c3 (6.7), 5cba3f5a8 (dev), 21dfc2508 (6.7)

    Description

      I think this ought to be possible:

              TextArea {
                  textDocument.onStatusChanged: {
                      const statusMessages = {
                          TextDocument.ReadError: "Failed to load ",
                          TextDocument.WriteError: "Failed to save ",
                          TextDocument.NonLocalFileError: "Not a local file: ",
                      }
                      const err = statusMessages[textDocument.status]
                      if (err) {
                          errorDialog.text = err
                          errorDialog.open()
                      }
                  }
      

      I'd go even further and put the string table into a property rather than needing to re-construct this const object each time the statusChanged callback occurs. (So what type should the property be then?) But either way, there is an error; in this case it says

      texteditor.qml:500:33: Expected token `,'
      

      I guess it doesn't expect a dot operator to occur in the key definition; whereas using a plain hard-coded number as a key is fine.

      https://codereview.qt-project.org/c/qt/qtdeclarative/+/537373 tries to modify the texteditor example in this way.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            srutledg Shawn Rutledge
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes