Uploaded image for project: 'Qt for MCUs'
  1. Qt for MCUs
  2. QTMCU-241

.js files cannot be imported to the qml document while it's possible in the big qt

    XMLWordPrintable

Details

    Description

      in the big qt documentation about importing js files(https://doc.qt.io/qt-6/qtqml-syntax-imports.html#javascript-resource-imports), it's said that developers can import .js files into the qml document and use the functions defined in it.

      i've tried if this also works in qt for mcus projects.

      it turned out, with this code, qt for mcus application didn't compile:

      // JSexperiment.qml
      import QtQuick
      import "myjs.js" as JS
      Rectangle {
          Text {
              anchors.centerIn: parent
              text: "Qt for MCUs"
          }
          Component.onCompleted: {
              console.log("Qt for MCUs is ready!")
              JS.func()
          }
      }
      
      // myjs.js
      function func() {
          console.log("form js")
      }  

      the error:

      C:/Users/81808/Downloads/JSexperiment/JSexperiment.qml:2:1: error: path 'myjs.js' not found
      import "myjs.js" as JS 

      in the meantime, the code worked in the big qt 6.6:

      // Main.qml
      import QtQuick
      import QtQuick.Window
      import "myjs.js" as JS
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          Component.onCompleted: {
              console.log("Qt for MCUs is ready!")
              JS.func()
          }
      }
       
      // myjs.js
      function func() {
          console.log("form js")
      }

      i've checked if this is written in the known issues or limitations of qt for mcus 2.6 but i couldn't find it.

      https://doc.qt.io/QtForMCUs-2.6/qtul-known-issues.html

      the projects used for the experiment are attached to this Jira ticket.

      Attachments

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

        Activity

          People

            tommit Tommi Tauriainen
            mikio_hirai Mikio Hirai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes