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

Attached properties are missing inside mjs modules

    XMLWordPrintable

Details

    Description

      main.qml:

      import QtQuick 2.12
      import QtQuick.Window 2.12
      //import './app.js' as App // works fine
      import './app.mjs' as App // produces error
      
      Window {
          visible: true
          width: 720
          height: 480
          title: qsTr("Keys")
      
          Rectangle {
              id: rect
              anchors.fill: parent
              focus: true
              Keys.onPressed: {
                  console.log('qml.rect.Keys.onPressed', event.key)
              }
          }
      
          Component.onCompleted: {
              App.main(rect) // inconsistent behavior here
          }
      }
      

      app.mjs:

      export function main(rect) {
          console.log('mjs.rect.Keys', rect.Keys); // prints undefined
          console.log('mjs.rect.Component', rect.Component); // prints  undefined
          rect.Keys.pressed.connect((e) => { // throws TypeError
              console.log('mjs.rect.Keys.pressed', e.key);
          });
      }
      

      app.js:

      function main(rect) {
          console.log('js.rect.Keys', rect.Keys); // prints QQuickKeysAttached(...)
          console.log('js.rect.Component', rect.Component); // prints QQmlComponentAttached(...)
          rect.Keys.pressed.connect((e) => { // emit events
              console.log('js.rect.Keys.pressed', e.key);
          });
      }
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            evg656e Evgeny
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes