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

Problem with ".pragma library" and scripts in resources

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.4.0 Beta
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Windows, msvc2013

      Description

      I have an application with different QML documents, of which some are loaded via Loaders. There is also one JS wile with ".pragma library". The QML files share data via that JS file.

      This works well in non-compiled QML or when using the qtquickcompiler 1.1 (shipped with Qt 5.3). But when using the qtquickcompiler 2.0 (shipped with Qt 5.4), some QML files see different data in the JS file.

      Here the minimal example followed by its output:

      source.js:

      .pragma library
      var string = undefined;
      

      A.qml:

      import QtQuick 2.3
      import "source.js" as Source
      Item {
          Component.onCompleted: {
              Source.string = "Foo";
              console.log('A.qml set the string: ' + Source.string);
          }
      }
      

      B.qml:

      import QtQuick 2.3
      import "source.js" as Source
      Item {
          Component.onCompleted: {
              Source.string += "Bar";
              console.log('B.qml appended a string: ' + Source.string);
          }
      }
      

      main.qml:

      import QtQuick 2.3
      import QtQuick.Window 2.2
      import "source.js" as Source
      Window {
          visible: true; width: 360; height: 360
      
          Loader { source: "B.qml" }
          Loader { source: "A.qml" }
          Component.onCompleted: {
              console.log('main.qml read the result: ' + Source.string);
          }
      }
      

      Output with qtquickcompiler 1.1 or non-compiled QML:

      qml: A.qml set the string: Foo
      qml: B.qml appended a string: FooBar
      qml: main.qml read the result: FooBar

      But in the faulty case, it does this:

      qml: A.qml set the string: Foo
      qml: B.qml appended a string: FooBar
      qml: main.qml read the result: undefined

      main.qml seems to have access to another "instance" of the JS file.

        Attachments

        1. QTBUG-42102.zip
          2 kB
        2. QTBUG-42102.zip
          2 kB

          Issue Links

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

            Activity

              People

              Assignee:
              shausman Simon Hausmann
              Reporter:
              portale Alessandro Portale
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes